TPC-H建表语句(MySQL语法)

TPC-H测试集介绍

TPC-H(Transaction Processing Performance Council, Standard Specification, Decision Support Benchmark, 简称TPC-H)是一个非常权威数据库基准测试程序,由TPC组织制定。

TPC-H定义了一个包含8个表的模式(Schema),这些表通过外键关联;下面是这八个表之间的关系以及MySQL语法的DDL语句。

TPC-H模式

TPC-H建表语句

sql 复制代码
CREATE TABLE REGION (
  R_REGIONKEY INT NOT NULL,
  R_NAME CHAR(25) NOT NULL,
  R_COMMENT VARCHAR(152) DEFAULT NULL,
  PRIMARY KEY (R_REGIONKEY)
) ENGINE=INNODB DEFAULT CHARSET=UTF8MB4 COLLATE=UTF8MB4_0900_AI_CI;
;

CREATE TABLE NATION (
  N_NATIONKEY INT NOT NULL,
  N_NAME CHAR(25) NOT NULL,
  N_REGIONKEY INT NOT NULL,
  N_COMMENT VARCHAR(152) DEFAULT NULL,
  PRIMARY KEY (N_NATIONKEY)
) ENGINE=INNODB DEFAULT CHARSET=UTF8MB4 COLLATE=UTF8MB4_0900_AI_CI;
;

CREATE TABLE PART (
  P_PARTKEY INT NOT NULL,
  P_NAME VARCHAR(55) NOT NULL,
  P_MFGR CHAR(25) NOT NULL,
  P_BRAND CHAR(10) NOT NULL,
  P_TYPE VARCHAR(25) NOT NULL,
  P_SIZE INT NOT NULL,
  P_CONTAINER CHAR(10) NOT NULL,
  P_RETAILPRICE DECIMAL(15,2) NOT NULL,
  P_COMMENT VARCHAR(23) NOT NULL,
  PRIMARY KEY (P_PARTKEY)
) ENGINE=INNODB DEFAULT CHARSET=UTF8MB4 COLLATE=UTF8MB4_0900_AI_CI;
;
CREATE TABLE CUSTOMER (
  C_CUSTKEY INT NOT NULL,
  C_NAME VARCHAR(25) NOT NULL,
  C_ADDRESS VARCHAR(40) NOT NULL,
  C_NATIONKEY INT NOT NULL,
  C_PHONE CHAR(15) NOT NULL,
  C_ACCTBAL DECIMAL(15,2) NOT NULL,
  C_MKTSEGMENT CHAR(10) NOT NULL,
  C_COMMENT VARCHAR(117) NOT NULL,
  PRIMARY KEY (C_CUSTKEY),
  KEY CUSTOMER_FK1 (C_NATIONKEY),
  CONSTRAINT CUSTOMER_IBFK_1 FOREIGN KEY (C_NATIONKEY) REFERENCES NATION (N_NATIONKEY)
) ENGINE=INNODB DEFAULT CHARSET=UTF8MB4 COLLATE=UTF8MB4_0900_AI_CI;
;

CREATE TABLE ORDERS (
  O_ORDERKEY INT NOT NULL,
  O_CUSTKEY INT NOT NULL,
  O_ORDERSTATUS CHAR(1) NOT NULL,
  O_TOTALPRICE DECIMAL(15,2) NOT NULL,
  O_ORDERDATE DATE NOT NULL,
  O_ORDERPRIORITY CHAR(15) NOT NULL,
  O_CLERK CHAR(15) NOT NULL,
  O_SHIPPRIORITY INT NOT NULL,
  O_COMMENT VARCHAR(79) NOT NULL,
  PRIMARY KEY (O_ORDERKEY),
  KEY ORDERS_FK1 (O_CUSTKEY),
  CONSTRAINT ORDERS_IBFK_1 FOREIGN KEY (O_CUSTKEY) REFERENCES CUSTOMER (C_CUSTKEY)
) ENGINE=INNODB DEFAULT CHARSET=UTF8MB4 COLLATE=UTF8MB4_0900_AI_CI;
;


CREATE TABLE SUPPLIER (
  S_SUPPKEY INT NOT NULL,
  S_NAME CHAR(25) NOT NULL,
  S_ADDRESS VARCHAR(40) NOT NULL,
  S_NATIONKEY INT NOT NULL,
  S_PHONE CHAR(15) NOT NULL,
  S_ACCTBAL DECIMAL(15,2) NOT NULL,
  S_COMMENT VARCHAR(101) NOT NULL,
  PRIMARY KEY (S_SUPPKEY),
  KEY SUPPLIER_FK1 (S_NATIONKEY),
  CONSTRAINT SUPPLIER_IBFK_1 FOREIGN KEY (S_NATIONKEY) REFERENCES NATION (N_NATIONKEY)
) ENGINE=INNODB DEFAULT CHARSET=UTF8MB4 COLLATE=UTF8MB4_0900_AI_CI;
;


CREATE TABLE PARTSUPP (
  PS_PARTKEY INT NOT NULL,
  PS_SUPPKEY INT NOT NULL,
  PS_AVAILQTY INT NOT NULL,
  PS_SUPPLYCOST DECIMAL(15,2) NOT NULL,
  PS_COMMENT VARCHAR(199) NOT NULL,
  PRIMARY KEY (PS_PARTKEY,PS_SUPPKEY),
  KEY PARTSUPP_FK1 (PS_SUPPKEY),
  CONSTRAINT PARTSUPP_IBFK_1 FOREIGN KEY (PS_SUPPKEY) REFERENCES SUPPLIER (S_SUPPKEY),
  CONSTRAINT PARTSUPP_IBFK_2 FOREIGN KEY (PS_PARTKEY) REFERENCES PART (P_PARTKEY)
) ENGINE=INNODB DEFAULT CHARSET=UTF8MB4 COLLATE=UTF8MB4_0900_AI_CI;
;

CREATE TABLE LINEITEM (
  L_ORDERKEY INT NOT NULL,
  L_PARTKEY INT NOT NULL,
  L_SUPPKEY INT NOT NULL,
  L_LINENUMBER INT NOT NULL,
  L_QUANTITY DECIMAL(15,2) NOT NULL,
  L_EXTENDEDPRICE DECIMAL(15,2) NOT NULL,
  L_DISCOUNT DECIMAL(15,2) NOT NULL,
  L_TAX DECIMAL(15,2) NOT NULL,
  L_RETURNFLAG CHAR(1) NOT NULL,
  L_LINESTATUS CHAR(1) NOT NULL,
  L_SHIPDATE DATE NOT NULL,
  L_COMMITDATE DATE NOT NULL,
  L_RECEIPTDATE DATE NOT NULL,
  L_SHIPINSTRUCT CHAR(25) NOT NULL,
  L_SHIPMODE CHAR(10) NOT NULL,
  L_COMMENT VARCHAR(44) NOT NULL,
  PRIMARY KEY (L_ORDERKEY,L_LINENUMBER),
  KEY LINEITEM_FK2 (L_PARTKEY,L_SUPPKEY),
  CONSTRAINT LINEITEM_IBFK_1 FOREIGN KEY (L_ORDERKEY) REFERENCES ORDERS (O_ORDERKEY),
  CONSTRAINT LINEITEM_IBFK_2 FOREIGN KEY (L_PARTKEY, L_SUPPKEY) REFERENCES PARTSUPP (PS_PARTKEY, PS_SUPPKEY)
) ENGINE=INNODB DEFAULT CHARSET=UTF8MB4 COLLATE=UTF8MB4_0900_AI_CI;
;

关于PawSQL

PawSQL专注数据库性能优化的自动化和智能化,提供的解决方案覆盖SQL开发、测试、运维的整个流程,支持MySQL,PostgreSQL,openGauss,Oracle等数据库。

相关推荐
苹果醋31 小时前
React源码02 - 基础知识 React API 一览
java·运维·spring boot·mysql·nginx
了一li1 小时前
Qt中的QProcess与Boost.Interprocess:实现多进程编程
服务器·数据库·qt
码农君莫笑2 小时前
信管通低代码信息管理系统应用平台
linux·数据库·windows·低代码·c#·.net·visual studio
别致的影分身2 小时前
使用C语言连接MySQL
数据库·mysql
过过过呀Glik2 小时前
在 Ubuntu 上安装 MySQL 的详细指南
mysql·ubuntu
京东零售技术4 小时前
“慢”增长时代的企业数据体系建设:超越数据中台
数据库
sdaxue.com4 小时前
帝国CMS:如何去掉帝国CMS登录界面的认证码登录
数据库·github·网站·帝国cms·认证码
o(╥﹏╥)5 小时前
linux(ubuntu )卡死怎么强制重启
linux·数据库·ubuntu·系统安全
阿里嘎多学长5 小时前
docker怎么部署高斯数据库
运维·数据库·docker·容器
Yuan_o_5 小时前
Linux 基本使用和程序部署
java·linux·运维·服务器·数据库·后端