当前位置:   article > 正文

TPC-H生成数据集并导入数据库

tpch生成数据

一.生成数据集
1.下载TPC-H压缩包

下载地址:http://www.tpc.org/tpc_documents_current_versions/current_specifications.asp

2.解压TPC-H的压缩包,进入dbgen文件夹,找到tpch.sln文件,用visual studio打开。

3.在工程处右键dbgen,选择生成,执行完毕

clip_image002[8]

4.此时,在dbgen文件夹下,出现了debug文件夹,在debug文件夹中,找到dbgen.exe的文件。copy到上一层目录,也就是dbgen文件夹中。

5.在dbgen文件夹下,打开dos界面。(在文件地址栏输入cmd)。输入命令dbgen -h

clip_image004[6]

clip_image006[6]

5.运行完后直接输入dbgen -vf -s XXX就可以生成你想要的数据了。这里的XXX表示想要生成的数据量(单位GB)

clip_image008[6]

6.生成结束后,就能在dbgen文件夹下面看到生成的数据集了。生成完毕(20GB)

clip_image010[6]

clip_image012[6]

二.导入数据

1.新建一个数据库用于导入数据

clip_image014[6]

2.建表sql

clip_image016[6]

3.建立表约束

clip_image018[6]

4.导入数据

clip_image020[6]

clip_image022[6]

5.查看导入的数据

clip_image024[6]

6.TPC-H数据集表关系图

数据集表关系图

三.SQL语句

  1. use Big
  2. ------------1.建表
  3. CREATE TABLE NATION ( N_NATIONKEY INTEGER NOT NULL,
  4. N_NAME CHAR(25) NOT NULL,
  5. N_REGIONKEY INTEGER NOT NULL,
  6. N_COMMENT VARCHAR(152));
  7. CREATE TABLE REGION ( R_REGIONKEY INTEGER NOT NULL,
  8. R_NAME CHAR(25) NOT NULL,
  9. R_COMMENT VARCHAR(152));
  10. CREATE TABLE PART ( P_PARTKEY INTEGER NOT NULL,
  11. P_NAME VARCHAR(55) NOT NULL,
  12. P_MFGR CHAR(25) NOT NULL,
  13. P_BRAND CHAR(10) NOT NULL,
  14. P_TYPE VARCHAR(25) NOT NULL,
  15. P_SIZE INTEGER NOT NULL,
  16. P_CONTAINER CHAR(10) NOT NULL,
  17. P_RETAILPRICE DECIMAL(15,2) NOT NULL,
  18. P_COMMENT VARCHAR(23) NOT NULL );
  19. CREATE TABLE SUPPLIER ( S_SUPPKEY INTEGER NOT NULL,
  20. S_NAME CHAR(25) NOT NULL,
  21. S_ADDRESS VARCHAR(40) NOT NULL,
  22. S_NATIONKEY INTEGER NOT NULL,
  23. S_PHONE CHAR(15) NOT NULL,
  24. S_ACCTBAL DECIMAL(15,2) NOT NULL,
  25. S_COMMENT VARCHAR(101) NOT NULL);
  26. CREATE TABLE PARTSUPP ( PS_PARTKEY INTEGER NOT NULL,
  27. PS_SUPPKEY INTEGER NOT NULL,
  28. PS_AVAILQTY INTEGER NOT NULL,
  29. PS_SUPPLYCOST DECIMAL(15,2) NOT NULL,
  30. PS_COMMENT VARCHAR(199) NOT NULL );
  31. CREATE TABLE CUSTOMER ( C_CUSTKEY INTEGER NOT NULL,
  32. C_NAME VARCHAR(25) NOT NULL,
  33. C_ADDRESS VARCHAR(40) NOT NULL,
  34. C_NATIONKEY INTEGER NOT NULL,
  35. C_PHONE CHAR(15) NOT NULL,
  36. C_ACCTBAL DECIMAL(15,2) NOT NULL,
  37. C_MKTSEGMENT CHAR(10) NOT NULL,
  38. C_COMMENT VARCHAR(117) NOT NULL);
  39. CREATE TABLE ORDERS ( O_ORDERKEY INTEGER NOT NULL,
  40. O_CUSTKEY INTEGER NOT NULL,
  41. O_ORDERSTATUS CHAR(1) NOT NULL,
  42. O_TOTALPRICE DECIMAL(15,2) NOT NULL,
  43. O_ORDERDATE DATE NOT NULL,
  44. O_ORDERPRIORITY CHAR(15) NOT NULL,
  45. O_CLERK CHAR(15) NOT NULL,
  46. O_SHIPPRIORITY INTEGER NOT NULL,
  47. O_COMMENT VARCHAR(79) NOT NULL);
  48. CREATE TABLE LINEITEM ( L_ORDERKEY INTEGER NOT NULL,
  49. L_PARTKEY INTEGER NOT NULL,
  50. L_SUPPKEY INTEGER NOT NULL,
  51. L_LINENUMBER INTEGER NOT NULL,
  52. L_QUANTITY DECIMAL(15,2) NOT NULL,
  53. L_EXTENDEDPRICE DECIMAL(15,2) NOT NULL,
  54. L_DISCOUNT DECIMAL(15,2) NOT NULL,
  55. L_TAX DECIMAL(15,2) NOT NULL,
  56. L_RETURNFLAG CHAR(1) NOT NULL,
  57. L_LINESTATUS CHAR(1) NOT NULL,
  58. L_SHIPDATE DATE NOT NULL,
  59. L_COMMITDATE DATE NOT NULL,
  60. L_RECEIPTDATE DATE NOT NULL,
  61. L_SHIPINSTRUCT CHAR(25) NOT NULL,
  62. L_SHIPMODE CHAR(10) NOT NULL,
  63. L_COMMENT VARCHAR(44) NOT NULL);
  64. ------------2.建立表约束
  65. use Big
  66. --ALTER TABLE Example.REGION DROP PRIMARY KEY;
  67. --ALTER TABLE Example.NATION DROP PRIMARY KEY;
  68. --ALTER TABLE Example.PART DROP PRIMARY KEY;
  69. --ALTER TABLE Example.SUPPLIER DROP PRIMARY KEY;
  70. --ALTER TABLE Example.PARTSUPP DROP PRIMARY KEY;
  71. --ALTER TABLE Example.ORDERS DROP PRIMARY KEY;
  72. --ALTER TABLE Example.LINEITEM DROP PRIMARY KEY;
  73. --ALTER TABLE Example.CUSTOMER DROP PRIMARY KEY;
  74. -- For table REGION
  75. ALTER TABLE dbo.REGION
  76. ADD PRIMARY KEY (R_REGIONKEY);
  77. -- For table NATION
  78. ALTER TABLE dbo.NATION
  79. ADD PRIMARY KEY (N_NATIONKEY);
  80. ALTER TABLE dbo.NATION
  81. ADD constraint NATION_FK1 FOREIGN KEY(N_REGIONKEY) references dbo.REGION(R_REGIONKEY);
  82. -- For table PART
  83. ALTER TABLE dbo.PART
  84. ADD PRIMARY KEY (P_PARTKEY);
  85. -- For table SUPPLIER
  86. ALTER TABLE dbo.SUPPLIER
  87. ADD PRIMARY KEY (S_SUPPKEY);
  88. ALTER TABLE dbo.SUPPLIER
  89. ADD constraint SUPPLIER_FK1 FOREIGN KEY(S_NATIONKEY) references dbo.NATION(N_NATIONKEY);
  90. -- For table PARTSUPP
  91. ALTER TABLE dbo.PARTSUPP
  92. ADD PRIMARY KEY (PS_PARTKEY,PS_SUPPKEY);
  93. -- For table CUSTOMER
  94. ALTER TABLE dbo.CUSTOMER
  95. ADD PRIMARY KEY (C_CUSTKEY);
  96. ALTER TABLE dbo.CUSTOMER
  97. ADD constraint CUSTOMER_FK1 FOREIGN KEY (C_NATIONKEY) references dbo.NATION(N_NATIONKEY);
  98. -- For table LINEITEM
  99. ALTER TABLE dbo.LINEITEM
  100. ADD PRIMARY KEY (L_ORDERKEY,L_LINENUMBER);
  101. -- For table ORDERS
  102. ALTER TABLE dbo.ORDERS
  103. ADD PRIMARY KEY (O_ORDERKEY);
  104. -- For table PARTSUPP
  105. ALTER TABLE dbo.PARTSUPP
  106. ADD constraint PARTSUPP_FK1 FOREIGN KEY (PS_SUPPKEY) references dbo.SUPPLIER(S_SUPPKEY);
  107. ALTER TABLE dbo.PARTSUPP
  108. ADD constraint PARTSUPP_FK2 FOREIGN KEY (PS_PARTKEY) references dbo.PART(P_PARTKEY);
  109. -- For table ORDERS
  110. ALTER TABLE dbo.ORDERS
  111. ADD constraint ORDERS_FK1 FOREIGN KEY (O_CUSTKEY) references dbo.CUSTOMER(C_CUSTKEY);
  112. -- For table LINEITEM
  113. ALTER TABLE dbo.LINEITEM
  114. ADD constraint LINEITEM_FK1 FOREIGN KEY (L_ORDERKEY) references dbo.ORDERS(O_ORDERKEY);
  115. ALTER TABLE dbo.LINEITEM
  116. ADD constraint LINEITEM_FK2 FOREIGN KEY (L_PARTKEY,L_SUPPKEY) references
  117. dbo.PARTSUPP(PS_PARTKEY, PS_SUPPKEY);
  118. ------------3.导入数据
  119. use Big
  120. BULK INSERT part FROM 'D:\JAVA\TPC-H\dbgen\part.tbl' WITH (TABLOCK, DATAFILETYPE='char', CODEPAGE='raw', FIELDTERMINATOR = '|')
  121. BULK INSERT customer FROM 'D:\JAVA\TPC-H\dbgen\customer.tbl' WITH (TABLOCK, DATAFILETYPE='char', CODEPAGE='raw', FIELDTERMINATOR = '|')
  122. BULK INSERT orders FROM 'D:\JAVA\TPC-H\dbgen\orders.tbl' WITH (TABLOCK, DATAFILETYPE='char', CODEPAGE='raw', FIELDTERMINATOR = '|')
  123. BULK INSERT partsupp FROM 'D:\JAVA\TPC-H\dbgen\partsupp.tbl' WITH (TABLOCK, DATAFILETYPE='char', CODEPAGE='raw', FIELDTERMINATOR = '|')
  124. BULK INSERT supplier FROM 'D:\JAVA\TPC-H\dbgen\supplier.tbl' WITH (TABLOCK, DATAFILETYPE='char', CODEPAGE='raw', FIELDTERMINATOR = '|')
  125. BULK INSERT lineitem FROM 'D:\JAVA\TPC-H\dbgen\lineitem.tbl' WITH (TABLOCK, DATAFILETYPE='char', CODEPAGE='raw', FIELDTERMINATOR = '|')
  126. BULK INSERT nation FROM 'D:\JAVA\TPC-H\dbgen\nation.tbl' WITH (TABLOCK, DATAFILETYPE='char', CODEPAGE='raw', FIELDTERMINATOR = '|')
  127. BULK INSERT region FROM 'D:\JAVA\TPC-H\dbgen\region.tbl' WITH (TABLOCK, DATAFILETYPE='char', CODEPAGE='raw', FIELDTERMINATOR = '|')
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/935529
推荐阅读
相关标签
  

闽ICP备14008679号