-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScript_CreateDatabase&Tables.sql
More file actions
59 lines (53 loc) · 1.72 KB
/
Script_CreateDatabase&Tables.sql
File metadata and controls
59 lines (53 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
-- Step 1: Create the Database
DROP DATABASE IF EXISTS Restaurant_DB;
CREATE DATABASE Restaurant_DB;
USE Restaurant_DB;
-- Step 2: Create all the tables. The order is based on the tables' dependencies.
-- Create Items table
CREATE TABLE Items (
item_id VARCHAR(10) PRIMARY KEY,
item_name VARCHAR(100) NOT NULL,
item_category VARCHAR(100) NOT NULL,
item_size VARCHAR(10) NOT NULL,
item_price DECIMAL(10, 2) NOT NULL
);
-- Create Ingredients table
CREATE TABLE Ingredients (
ingredient_id VARCHAR(10) PRIMARY KEY,
ingredient_name VARCHAR(200) NOT NULL,
measurement VARCHAR(20) NOT NULL,
ingredient_price DECIMAL(5, 2) NOT NULL
);
-- Create ItemIngredients table
CREATE TABLE ItemIngredients (
item_id VARCHAR(10),
ingredient_id VARCHAR(10),
quantity_required INT NOT NULL,
PRIMARY KEY (item_id, ingredient_id),
FOREIGN KEY (item_id) REFERENCES Items(item_id),
FOREIGN KEY (ingredient_id) REFERENCES Ingredients(ingredient_id)
);
-- Create Orders table
CREATE TABLE Orders (
order_id VARCHAR(10) PRIMARY KEY,
placement_date DATETIME NOT NULL
);
-- Create OrderItems table
CREATE TABLE OrderItems (
order_item_id INT AUTO_INCREMENT PRIMARY KEY,
order_id VARCHAR(10),
item_id VARCHAR(10),
quantity INT NOT NULL,
item_price DECIMAL(10, 2) NOT NULL,
FOREIGN KEY (order_id) REFERENCES Orders(order_id),
FOREIGN KEY (item_id) REFERENCES Items(item_id)
);
-- Create Inventory table
CREATE TABLE Inventory (
inventory_id INT AUTO_INCREMENT PRIMARY KEY,
item_id VARCHAR(10),
ingredient_id VARCHAR(10),
quantity INT NOT NULL,
FOREIGN KEY (item_id) REFERENCES Items(item_id),
FOREIGN KEY (ingredient_id) REFERENCES Ingredients(ingredient_id)
);