-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassign12 DBcreation.txt
42 lines (36 loc) · 1.32 KB
/
assign12 DBcreation.txt
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
create table Customer (
CUSTOMER_ID INT NOT NULL AUTO_INCREMENT,
name varchar(20),
discountRate INT,
PRIMARY KEY (CUSTOMER_ID)
);
create table Ordert (
order_id INT NOT NULL AUTO_INCREMENT,
ORDER_CUSTOMER_FK int,
order_date date,
PRIMARY KEY (order_id),
FOREIGN KEY(ORDER_CUSTOMER_FK) REFERENCES customer(CUSTOMER_ID)
);
create table Product (
PRODUCT_ID INT NOT NULL AUTO_INCREMENT,
PRODUCT_NAME varchar(20),
PRIMARY KEY (PRODUCT_ID)
);
create table OrderItem (
ORDER_ITEM_ID INT NOT NULL AUTO_INCREMENT,
ORDER_ITEM_ORDER_FK INT,
ORDER_ITEM_PRODUCT_FK INT,
ORDER_ITEM_COUNT int,
PRIMARY KEY (ORDER_ITEM_ID),
FOREIGN KEY(ORDER_ITEM_ORDER_FK) REFERENCES customer(ORDER_ID),
FOREIGN KEY(ORDER_ITEM_PRODUCT_FK) REFERENCES customer(PRODUCT_ID)
);
create table OrderItem (
ORDER_ITEM_ID INT NOT NULL AUTO_INCREMENT,
ORDER_ITEM_ORDER_FK INT,
ORDER_ITEM_PRODUCT_FK INT,
ORDER_ITEM_COUNT int,
PRIMARY KEY (ORDER_ITEM_ID),
FOREIGN KEY(ORDER_ITEM_ORDER_FK) REFERENCES ordert(ORDER_ID),
FOREIGN KEY(ORDER_ITEM_PRODUCT_FK) REFERENCES product(PRODUCT_ID)
);