CSCE 520
Homework 3

Reading

Finish Chapter 2. Read Section 5.1.

To submit

The hardcopy exercises together are worth 70% and the MySQL exercise 30%.

Undergrads and graduate students
Do Exercises 2.4.7, 2.4.8 (undergrad extra credit), 2.5.1(a,b,c) (hardcopy).
MySQL exercise (dropbox): Add the following constraints to your database schema from Homework2, exercises 2.3.1 and 2.4.1:

  1. The model attribute forms a primary key for Product, PC, Laptop, and Printer. (Four key constraints)
  2. The type of a product cannot be null.
  3. Every model that appears in PC, Laptop, or Printer must also appear as a model in Product. (Three referential integrity/foreign key constraints).
  4. Constrain the type of a product to be either 'pc', 'laptop', 'printer', 'smartphone', or 'tablet'. (One domain/check constraint)
You should include these constraints with the CREATE TABLE commands and recreate the database from scratch, as you did in Homework 2. (You could add the constraints directly--without disturbing data--with ALTER TABLE commands, described in class, but then your file cannot be tested from scratch by the TA.)

Once you are satisfied that you have the correct commands, put them all in a single file hw3.sql along with the data insertion commands from HW2. Then try the following commands in MySQL (assuming the original data was entered exactly as in Figures 2.20 and 2.21):

insert into Product(maker, model) values('I', 1014);
insert into Product values('J', 4001, 'toaster');
insert into Laptop values (2001, 3.00, 1024, 480, 15.6, 1995);
delete from Product where model=1001;
select * from Printer;
delete from Product where model=3001;
select * from Printer;
rollback;

All the data-altering commands above should be disallowed, with an error message given, except for the last one, which should also alter the Printer table instance. Add these commands to the bottom of your hw3.sql file. Exit MySQL, and at the shell prompt, type

mysql -p -e "source hw3.sql" sales > hw3.txt

Submit a .zip file containing the two files hw3.sql and hw3.txt.

Graduate students only
Do Exercises 2.4.8 (for full credit), 2.5.1(d,e) (hardcopy)