-
Notifications
You must be signed in to change notification settings - Fork 2
/
sqlite-ddl.sql
94 lines (87 loc) · 2.76 KB
/
sqlite-ddl.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
CREATE TABLE REGION (
R_REGIONKEY INTEGER PRIMARY KEY NOT NULL,
R_NAME TEXT NOT NULL,
R_COMMENT TEXT
);
CREATE TABLE NATION (
N_NATIONKEY INTEGER PRIMARY KEY NOT NULL,
N_NAME TEXT NOT NULL,
N_REGIONKEY INTEGER NOT NULL,
N_COMMENT TEXT,
FOREIGN KEY (N_REGIONKEY) REFERENCES REGION(R_REGIONKEY)
);
CREATE TABLE PART (
P_PARTKEY INTEGER PRIMARY KEY NOT NULL,
P_NAME TEXT NOT NULL,
P_MFGR TEXT NOT NULL,
P_BRAND TEXT NOT NULL,
P_TYPE TEXT NOT NULL,
P_SIZE INTEGER NOT NULL,
P_CONTAINER TEXT NOT NULL,
P_RETAILPRICE DOUBLE NOT NULL,
P_COMMENT TEXT NOT NULL
);
CREATE TABLE SUPPLIER (
S_SUPPKEY INTEGER PRIMARY KEY NOT NULL,
S_NAME TEXT NOT NULL,
S_ADDRESS TEXT NOT NULL,
S_NATIONKEY INTEGER NOT NULL,
S_PHONE TEXT NOT NULL,
S_ACCTBAL DOUBLE NOT NULL,
S_COMMENT TEXT NOT NULL,
FOREIGN KEY (S_NATIONKEY) REFERENCES NATION(N_NATIONKEY)
);
CREATE TABLE PARTSUPP (
PS_PARTKEY INTEGER NOT NULL,
PS_SUPPKEY INTEGER NOT NULL,
PS_AVAILQTY INTEGER NOT NULL,
PS_SUPPLYCOST DOUBLE NOT NULL,
PS_COMMENT TEXT NOT NULL,
PRIMARY KEY (PS_PARTKEY, PS_SUPPKEY),
FOREIGN KEY (PS_SUPPKEY) REFERENCES SUPPLIER(S_SUPPKEY),
FOREIGN KEY (PS_PARTKEY) REFERENCES PART(P_PARTKEY)
);
CREATE TABLE CUSTOMER (
C_CUSTKEY INTEGER PRIMARY KEY NOT NULL,
C_NAME TEXT NOT NULL,
C_ADDRESS TEXT NOT NULL,
C_NATIONKEY INTEGER NOT NULL,
C_PHONE TEXT NOT NULL,
C_ACCTBAL DOUBLE NOT NULL,
C_MKTSEGMENT TEXT NOT NULL,
C_COMMENT TEXT NOT NULL,
FOREIGN KEY (C_NATIONKEY) REFERENCES NATION(N_NATIONKEY)
);
CREATE TABLE ORDERS (
O_ORDERKEY INTEGER PRIMARY KEY NOT NULL,
O_CUSTKEY INTEGER NOT NULL,
O_ORDERSTATUS TEXT NOT NULL,
O_TOTALPRICE DOUBLE NOT NULL,
O_ORDERDATE STRING NOT NULL,
O_ORDERPRIORITY TEXT NOT NULL,
O_CLERK TEXT NOT NULL,
O_SHIPPRIORITY INTEGER NOT NULL,
O_COMMENT TEXT NOT NULL,
FOREIGN KEY (O_CUSTKEY) REFERENCES CUSTOMER(C_CUSTKEY)
);
CREATE TABLE LINEITEM (
L_ORDERKEY INTEGER NOT NULL,
L_PARTKEY INTEGER NOT NULL,
L_SUPPKEY INTEGER NOT NULL,
L_LINENUMBER INTEGER NOT NULL,
L_QUANTITY INTEGER NOT NULL,
L_EXTENDEDPRICE DOUBLE NOT NULL,
L_DISCOUNT DOUBLE NOT NULL,
L_TAX DOUBLE NOT NULL,
L_RETURNFLAG TEXT NOT NULL,
L_LINESTATUS TEXT NOT NULL,
L_SHIPDATE STRING NOT NULL,
L_COMMITDATE STRING NOT NULL,
L_RECEIPTDATE STRING NOT NULL,
L_SHIPINSTRUCT TEXT NOT NULL,
L_SHIPMODE TEXT NOT NULL,
L_COMMENT TEXT NOT NULL,
PRIMARY KEY (L_ORDERKEY, L_LINENUMBER),
FOREIGN KEY (L_ORDERKEY) REFERENCES ORDERS(O_ORDERKEY),
FOREIGN KEY (L_PARTKEY, L_SUPPKEY) REFERENCES PARTSUPP(PS_PARTKEY, PS_SUPPKEY)
);