-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreating_Tables.sql
78 lines (68 loc) · 1.97 KB
/
Creating_Tables.sql
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
DROP DATABASE RecipeBook;
CREATE DATABASE RecipeBook;
USE RecipeBook;
/*
DROP TABLE Cuisines;
DROP TABLE Types;
DROP TABLE Ingredients;
DROP TABLE RecipeInfo;
DROP TABLE RecipeIngredients;
DROP TABLE Equipment;
DROP TABLE RecipeEquipment;
DROP TABLE Calendar;
*/
CREATE TABLE Cuisines(
CuisineID INT PRIMARY KEY AUTO_INCREMENT,
CuisineName VARCHAR(20)
);
CREATE TABLE Types(
TypeID INT PRIMARY KEY AUTO_INCREMENT,
TypeName VARCHAR(15) NOT NULL
);
CREATE TABLE Ingredients(
IngredientID INT PRIMARY KEY AUTO_INCREMENT,
IngredientName VARCHAR(35) NOT NULL,
InStock BOOLEAN
);
CREATE TABLE RecipeInfo (
RecipeID INT PRIMARY KEY AUTO_INCREMENT,
Title VARCHAR(40) NOT NULL,
MainIngredient INT NOT NULL,
Servings INT,
PrepTimeMin INT,
CuisineID INT NOT NULL,
TypeID INT NOT NULL,
LinkToRecipe VARCHAR(200),
FOREIGN KEY (MainIngredient) REFERENCES Ingredients(IngredientID)
ON DELETE CASCADE,
FOREIGN KEY (CuisineID) REFERENCES Cuisines(CuisineID)
ON DELETE CASCADE
ON UPDATE CASCADE,
FOREIGN KEY (TypeID) REFERENCES Types(TypeID)
ON DELETE CASCADE,
CHECK (Servings > 0),
CHECK (PrepTimeMin > 0)
);
CREATE TABLE RecipeIngredients(
RecipeID INT NOT NULL,
IngredientID INT NOT NULL,
FOREIGN KEY (RecipeID) REFERENCES RecipeInfo(RecipeID) ON DELETE CASCADE,
FOREIGN KEY (IngredientID) REFERENCES Ingredients(IngredientID) ON DELETE CASCADE
);
CREATE TABLE Equipment(
EquipmentID INT PRIMARY KEY AUTO_INCREMENT,
NAME VARCHAR(30)
);
CREATE TABLE RecipeEquipment(
RecipeID INT NOT NULL,
EquipmentID INT NOT NULL,
FOREIGN KEY (RecipeID) REFERENCES RecipeInfo(RecipeID) ON DELETE CASCADE,
FOREIGN KEY (EquipmentID) REFERENCES Equipment(EquipmentID) ON DELETE CASCADE
);
CREATE TABLE Calendar(
LastEaten DATE NOT NULL,
RecipeID INT NOT NULL,
FOREIGN KEY (RecipeID) REFERENCES RecipeInfo(RecipeID) ON DELETE CASCADE
);
CREATE VIEW QuickMeals AS
SELECT Title FROM RecipeInfo WHERE PrepTimeMin <= 30;