Correcting sql, work on tables
This commit is contained in:
parent
83e82c93aa
commit
0416a1d3da
2 changed files with 8 additions and 10 deletions
|
@ -7,18 +7,16 @@ CREATE TABLE IF NOT EXISTS customers (
|
|||
customer_id int PRIMARY KEY,
|
||||
customer_name varchar(100),
|
||||
customer_address varchar(255)
|
||||
-- ...Perhaps more columns
|
||||
);
|
||||
|
||||
-- Orders from customers.
|
||||
-- Keep in mind that the delivery_date may be NULL
|
||||
CREATE TABLE IF NOT EXISTS Orders (
|
||||
CREATE TABLE IF NOT EXISTS orders (
|
||||
order_id int PRIMARY KEY,
|
||||
customer_id int,
|
||||
order_date date DEFAULT NOW(),
|
||||
order_date date DEFAULT NOW,
|
||||
delivery_date date, -- Set when the order hits the truck
|
||||
FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
|
||||
-- ...Perhaps more columns
|
||||
);
|
||||
|
||||
--------------------------------------------
|
||||
|
@ -28,7 +26,7 @@ CREATE TABLE IF NOT EXISTS Orders (
|
|||
-- Recipes for all the cookies (essentially a list of cookies)
|
||||
CREATE TABLE IF NOT EXISTS recipes (
|
||||
recipe_id int PRIMARY KEY,
|
||||
recipe_name varchar(100), -- Cookie name
|
||||
recipe_name varchar(100) -- Cookie name
|
||||
);
|
||||
|
||||
-- "The company has a raw materials warehouse in which
|
||||
|
@ -40,7 +38,7 @@ CREATE TABLE IF NOT EXISTS ingredients (
|
|||
ingredient_id int PRIMARY KEY,
|
||||
ingredient_name varchar(100),
|
||||
amount int,
|
||||
unit varchar(50),
|
||||
unit varchar(50)
|
||||
);
|
||||
|
||||
-- Describes what ingredients goes into what recipe
|
||||
|
@ -49,7 +47,7 @@ CREATE TABLE IF NOT EXISTS recipe_contents (
|
|||
recipe_id int,
|
||||
ingredient_id int,
|
||||
amount int,
|
||||
PRIMARY KEY (recipe_id, ingredient_id),
|
||||
PRIMARY KEY (recipe_id, ingredient_id)
|
||||
);
|
||||
|
||||
--------------------------------------------
|
||||
|
@ -80,6 +78,6 @@ CREATE TABLE IF NOT EXISTS pallet_contents (
|
|||
CREATE TABLE IF NOT EXISTS delivery_bill (
|
||||
delivery_id int PRIMARY KEY,
|
||||
order_id int,
|
||||
delivery_date date DEFAULT NOW(),
|
||||
delivery_date date DEFAULT NOW,
|
||||
FOREIGN KEY (order_id) REFERENCES Orders(order_id)
|
||||
);
|
|
@ -1,5 +1,5 @@
|
|||
-- Inserts here
|
||||
INSERT INTO
|
||||
INSERT OR IGNORE INTO
|
||||
customers (customer_id, customer_name, customer_address)
|
||||
VALUES
|
||||
(1, 'Bjudkakor AB', 'Ystad'),
|
||||
|
@ -12,7 +12,7 @@ VALUES
|
|||
(8, 'Småbröd AB', 'Malmö');
|
||||
|
||||
INSERT INTO
|
||||
recipes (name)
|
||||
recipes (recipe_name)
|
||||
VALUES
|
||||
('Nut ring'),
|
||||
('Nut cookie'),
|
||||
|
|
Loading…
Reference in a new issue