


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Number INT NOT NULL AUTO_INCREMENT, Number - create a column name called Number INT - set the Number column to Integer. NOT NULL - make the Number column not null. AUTO_INCREMENT - Make the Number column auto increment. PRIMARY KEY(Number) Indicates that the Number column is the primary key holder. My_Grocery_Lists Table with Primary Keys ( this will also be called the parent table ) CREATE TABLE My_Grocery_Lists ( Number INT NOT NULL AUTO_INCREMENT, Grocery_Items VARCHAR(30), Price DEC(6,2), Expiry_Date DATE, Stocks VARCHAR(20), PRIMARY KEY(Number) ); INSERT INTO My_Grocery_Lists VALUES ( 1, 'Milk', 40.2, '2023-01-10', '3 boxes' ); INSERT INTO My_Grocery_Lists VALUES ( 2, 'Rice', 160.2, '2023-02-15', '3 kl.' ); INSERT INTO My_Grocery_Lists VALUES ( 3, 'Pork', 120.2, '2022-02-10', '2 kl.' ); INSERT INTO My_Grocery_Lists VALUES ( 4, 'Chicken', 118.2, '2022-02-10', '3 kl.' ); INSERT INTO My_Grocery_Lists VALUES ( 5, 'Beef', 125.2, '2022-02-10', '3 kl.' ); SELECT * FROM My_Grocery_Lists;
Reminder: Do not put single quotes on non-decimals/numbers.
INSERT INTO Brands VALUES ( 1, 'Nestle', 1); INSERT INTO - command used for inserting values. Brands - the column where the values will be inserted. VALUES - the values to be inserted. 1 - the primary key of Nestle on this table. Nestle - the brand of milk. 1 - the foreign key ( the milks ID on the parent table (My_Grocery_Lists). INSERT INTO Brands VALUES ( 2, 'Japanese Rice',2); INSERT INTO - command used for inserting values. Brands - the column where the values will be inserted. VALUES - the values to be inserted. 2 - the primary key of Japanese Rice on this table. Japanese Rice - the brand of rice. 2 - the foreign key ( the rice ID on the parent table (My_Grocery_Lists). INSERT INTO Brands VALUES ( 3, 'Pork Roll', 3); INSERT INTO - command used for inserting values. Brands - the column where the values will be inserted. VALUES - the values to be inserted. 3 - the primary key of Pork Roll on this table. Pork Roll - the brand of rice. 3 - the foreign key ( the pork ID on the parent table (My_Grocery_Lists). INSERT INTO Brands VALUES ( 4, 'Magnolia', 4); INSERT INTO - command used for inserting values. Brands - the column where the values will be inserted. VALUES - the values to be inserted. 4 - the primary key of Magnolia on this table. Magnolia- the brand of rice. 4 - the foreign key ( the chicken ID on the parent table (My_Grocery_Lists). INSERT INTO Brands VALUES ( 5, 'Monterey', 5); INSERT INTO - command used for inserting values. Brands - the column where the values will be inserted. VALUES - the values to be inserted. 5 - the primary key of Monterey on this table. Monterey- the brand of rice. 5 - the foreign key ( the beef ID on the parent table (My_Grocery_Lists). Important: A foreign key is important in connecting tables as it enables relationship to the parent table. This will make other foreign keys unacceptable on other tables if it is not present on the parent table. Created By: mju2022 | Feb 13,2022 | 12:46 PM | LNC