This assignment practices SQL DDL.
Write the SQL DDL to create the following 5 tables describing cooking: Recipe
, Ingredient
, Author
, Cook
, Requires
. Make sure that every table has a primary key.
-
An
Author
table where each author is identified by an integerid
and has aname
(up to 30 characters). -
An
Ingredient
table where each ingredient has anid
of exactly 5 characters and aname
(up to 30 characters). -
A
Recipe
table where each recipe is identified by a field calledid
that is an integer. Other attributes includename
(string up to 40 characters),authorId
(integer), anddirections
(string up to 255 characters). Make all foreign keys set to null on delete and no action (generate error) on update. -
A
Cook
table where each time a recipe is made it is identified by a date/time (DATETIME). The table also has arecipe id
and acomment
(string up to 255 characters). Make all foreign keys set to perform cascade on delete and cascade on update. -
A
Requires
table that stores what ingredients are needed in a recipe. This table has arecipe id
,ingredient id
, andamount
(floating point number). Make all foreign keys set to cascade on both update and delete.
Write the SQL DDL to perform the following modifications to the database created in Question 1.
Insert the following records into the appropriate tables.
(1,'Joe Smith')
(2,'Fred Funk')
('BUTTR','Butter')
('FLOUR','Flour')
('MILK','Milk')
('EGGS','Eggs')
('SUGAR','Sugar')
(100,'Cookies',1,'Mix butter, flour, milk, eggs, and sugar. Then hope for the best.')
(200,'Bread',2,'Knead flour with milk and eggs. Bake at 450F or until brown.')
You figure it out based on both recipes (choose your own amount).
Recipe for bread was made on September 15, 2024 (no comment). Recipe for cookies was made on September 23rd, 2024 at 1:35:45 p.m. Comment: 'It actually worked!'
-
Change the name of the ingredient with id 'MILK' to 'Skim Milk'.
-
Increase the amount of all required ingredients used with recipe 100 by 2.
-
Delete all recipes written by 'Fred Funk'. How many rows are deleted when this statement is run? (1 mark) Note: In addition to testing when the foreign key is ON CASCADE, also recommend you try the DELETE when the foreign key on Recipe is either SET NULL or NO ACTION to see the difference.
-
Delete all ingredients required for recipe 200 with an amount greater than 2.
Submit the lab answers on Canvas as a text file or document that contains all of your SQL DDL commands or show a TA your SQL DDL commands in a help session.