CREATE DATABASE TPCH; USE TPCH;
CREATE TABLE Region (regionkey INTEGER PRIMARY KEY, name CHAR(25), comment VARCHAR(152)); LOAD DATA INFILE 'E:/DB/dbtestdata/region.csv' INTO TABLE Region FIELDS TERMINATED BY',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\r\n';
CREATE TABLE Nation (nationkey INTEGER PRIMARY KEY, name CHAR(25), regionkey INTEGER REFERENCES Region(regionkey), comment VARCHAR(152));
LOAD DATA INFILE 'E:/DB/dbtestdata/nation.csv' INTO TABLE Nation FIELDS TERMINATED BY',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\r\n';
CREATE TABLE Supplier (suppkey INTEGER PRIMARY KEY, name CHAR(25), address VARCHAR(40), nationkey INTEGER REFERENCES Nation(nationkey), phone CHAR(15), acctbal REAL, comment VARCHAR(101));
LOAD DATA INFILE 'E:/DB/dbtestdata/supplier.csv' INTO TABLE Supplier FIELDS TERMINATED BY',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\r\n' (suppkey,name,address,nationkey,phone);
CREATE TABLE Part (partkey INTEGER PRIMARY KEY, name VARCHAR(55), mfgr CHAR(25), brand CHAR(10), type VARCHAR(25), size INTEGER, container CHAR(10), retailprice REAL, comment VARCHAR(23));
LOAD DATA INFILE 'E:/DB/dbtestdata/part.csv' INTO TABLE Part FIELDS TERMINATED BY',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\r\n' (partkey,name,mfgr,type,retailprice);
CREATE TABLE PartSupp (partkey INTEGER REFERENCES Part(partkey), suppkey INTEGER REFERENCES Suppplier(suppkey), availqty INTEGER, supplycost REAL, comment VARCHAR(199), PRIMARY KEY(partkey,suppkey));
LOAD DATA INFILE 'E:/DB/dbtestdata/partsupp.csv' INTO TABLE PartSupp FIELDS TERMINATED BY',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\r\n' (partkey,suppkey,availqty,supplycost);
CREATE TABLE Customer (custkey INTEGER PRIMARY KEY, name CHAR(25), address VARCHAR(40), nationkey INTEGER REFERENCES Nation(nationkey), phone CHAR(15), acctbal REAL, mktsegment CHAR(10), comment VARCHAR(117));
LOAD DATA INFILE 'E:/DB/dbtestdata/customer.csv' INTO TABLE Customer FIELDS TERMINATED BY',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\r\n' (custkey,name,nationkey);
CREATE TABLE Orders (orderkey INTEGER PRIMARY KEY, custkey INTEGER REFERENCES Customer(custkey), orderstatus CHAR(1), totalprice REAL, orderdate DATE, orderpriority CHAR(15), clerk CHAR(15), shippriority INTEGER, comment VARCHAR(79));
LOAD DATA INFILE 'E:/DB/dbtestdata/orders.csv' INTO TABLE Orders FIELDS TERMINATED BY',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\r\n' (orderkey,custkey,orderdate);
CREATE TABLE Lineitem (orderkey INTEGER REFERENCES Orders(orderkey), partkey INTEGER REFERENCES Part(partkey), suppkey INTEGER REFERENCES Suppplier(suppkey), linenumber INTEGER, quantity REAL, extendedprice REAL, discount REAL, tax REAL, returnflag CHAR(1), linestatus CHAR(1), shipdate DATE, commitdate DATE, receiptdate DATE, shipinstruct CHAR(25), shipmode CHAR(10), comment VARCHAR(44), PRIMARY KEY(orderkey,linenumber), FOREIGN KEY(partkey,suppkey) REFERENCES PartSupp(partkey,suppkey));
LOAD DATA INFILE 'E:/DB/dbtestdata/lineitem.csv' INTO TABLE Lineitem FIELDS TERMINATED BY',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\r\n' (orderkey,partkey,suppkey,linenumber,quantity,discount,extendedprice);
|