CSE4_560 Homework3-Strengths and weaknesses of the trigger mechanism Solved

35.00 $

Category:

Description

5/5 - (2 votes)

 

  1.  Discuss the strengths and weaknesses of the trigger mechanism. Contrast triggers with other integrity constraints supported by SQL.
  2.  Consider a relation about people in the United States, including their name, Social Security number, street address, city, state, ZIP code, area code, and phone number (7 digits). What FD’s would you expect to hold? What are the keys for the relation? To answer this question, you need to know something about the way these numbers are assigned. For instance, can an area code straddle two states? Can a ZIP code straddle two area codes? Can two people have the same Social Security number? Can they have the same address or phone number?

3.Consider a relation representing the present position of molecules in a closed container. The attributes are an ID for the molecule, the x, y,and z coordinates of the molecule, and its velocity in the x, y, and z dimensions. What FD’s would you expect to hold? What are the keys?

  1.  Show that if a relation has no attribute that is functionally determined by all the other attributes, then the relation has no nontrivial FD’s at all.
  2.  Let X and Y be sets of attributes. Show that if XY , then X+Y+ , where the closures are taken with respect to the same set of FD’s.
  3.  Suppose we have a relation schema R(A, B, C) with FD A!B . Suppose also that we decide to decompose this schema into S(A, B) and T(B, C). Give an example of an instance of relation R whose projection onto S and T and subsequent rejoining does not yield the same relation instance.
  4.  Suppose we have relation R(A, B, C, D, E), with some set of FD’s, and we wish to project those FD’s onto relation S(A, B, C). Give the FD’s that hold in S if the FD’s for R

are: a)AB!AB!DE,EC, AC!E!, DED!, and, CD, and!DEA, and!EE!B!.AEA..!B.

  1. b) A!DD, BD, AC!!E, BC!

c)

  1. d) A!B, B!C, Ccient to give a minimal basis for the full set of FD’s of S!D, D!E, and In each case, it is su
  2. [12] Write the following constraints for attributes of the relation: Movies (title , year, length , genre, studioName, producerC)
  3. The year cannot be before 1915.
  4. The length cannot be less than 60 nor more than 250.
  5. The studio name can only be Disney, Fox, MGM, or Paramount.
  6. [12] Write the following constraints on attributes fro the below schema

Product(maker, model, type)

PC(model, speed, ram, hd, price )

Laptop(model, speed, ram, hd, screen , price )

Printer(model, color, type, price)

  1. The speed of a laptop must be at least 2.0.
  2. The only types of printers are laser, ink-jet, and bubble-jet.
  3. The only types of products are P C ’s, laptops, and printers.
  4. A model of a product must also be the model of a PC, a laptop, or a printer.
  5. [12] Write the following constraints as tuple-based CHECK constraints on one of the relations of our running movies example:

Movies (title , year, length , genre, studioName, producerC)

StarsIn (movie Title , movieYear, starName)

MovieStar(name, address, gender, birth date )

MovieExec(name, ad d ress, c e rt , netWorth)

Studio(nam e, ad d ress, presC)

If the constraint actually involves two relations, then you should put constraints in both relations so that whichever relation changes, the constraint will be checked on insertions and updates. Assume no deletions; it is not always possible to maintain tuple-based constraints in the face of deletions.

  1. A star may not appear in a movie made before they were born.
  2. No two studios may have the same address.
  3. A name that appears in MovieStar must not also appear in MovieExec.
  4. A studio name that appears in S tudio must also appear in at least one Movies tuple.
  5. [12] Show how to alter your relation schemas for the movie example:

Movie (title , year, length , genre, studioName, producerC)

Starsln (movie Title , movieYear, starName)

MovieStar(name, ad d ress, gender, birth date )

MovieExec(name, address, cert , netWorth) Studio(nam e, address, presC)

in the following ways.

  1. Make title and year the key for Movie.
  2. Require the referential integrity constraint that the producer of every movie appear inMovieExec.
  3. Require that no movie length be less than 60 nor greater than 250.
  4. Require that no name appear as both a movie star and movie executive (this constraintneed not be maintained in the face of deletions). e) Require that no two studios have the same address.
  5. [12] Write the following assertions. The database schema is from the “PC ” example of Q9 above:

Product(maker, model, type)

PC(model, speed, ram, hd, price )

Laptop(model, speed, ram, hd, screen , price )

Printer(model, color, type, price)

  1. No manufacturer of PC ’s may also make laptops.
  2. A manufacturer of a PC must also make a laptop with at least as great a processor speed.
  3. If a laptop has a larger main memory than a PC, then the laptop must also have a higherprice than the PC.
  4. If the relation Product mentions a model and its type, then this model must appear inthe relation appropriate to that type.

13.[3+3+4] Write the following as triggers. In each case, disallow or undo the modification if it does not satisfy the stated constraint. The database schema is from the “PC” example of Q9 above:

Product(maker, model, type)

PC(model, speed, ram, hd, price )

Laptop(model, speed, ram, hd, screen , price )

Printer(model, color, type, price)

  1. When updating the price of a PC, check that there is no lower priced PC with the samespeed.
  2. When inserting a new printer, check that the model number exists in Product.
  3. When making any modification to the Laptop relation, check that the average price oflaptops for each manufacturer is at least $1500.
  • HW3-avjwg0.zip