test-sql-script-postgresql.sql 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. CREATE TABLE T_ACCOUNT
  2. (
  3. ID INTEGER NOT NULL,
  4. NAME VARCHAR(20) NOT NULL,
  5. HEAD_IMG BYTEA,
  6. INTRODUCTION TEXT,
  7. PRIMARY KEY (ID)
  8. );
  9. COMMENT ON TABLE T_ACCOUNT IS '账号';
  10. COMMENT ON COLUMN T_ACCOUNT.NAME IS '帐号名';
  11. COMMENT ON COLUMN T_ACCOUNT.HEAD_IMG IS '头像图片';
  12. COMMENT ON COLUMN T_ACCOUNT.INTRODUCTION IS '自我介绍';
  13. CREATE TABLE T_ADDRESS
  14. (
  15. ACCOUNT_ID INTEGER NOT NULL,
  16. CITY VARCHAR(50),
  17. STREET VARCHAR(100),
  18. RESIDENTIAL VARCHAR(100),
  19. HOUSE_NUMBER VARCHAR(100)
  20. );
  21. ALTER TABLE T_ADDRESS ADD FOREIGN KEY (ACCOUNT_ID) REFERENCES T_ACCOUNT (ID);
  22. ALTER TABLE T_ADDRESS ADD CONSTRAINT UK_ACCOUNT_ID UNIQUE (ACCOUNT_ID);
  23. COMMENT ON TABLE T_ADDRESS IS '住址';
  24. COMMENT ON COLUMN T_ADDRESS.ACCOUNT_ID IS '所属帐号';
  25. COMMENT ON COLUMN T_ADDRESS.CITY IS '城市';
  26. COMMENT ON COLUMN T_ADDRESS.STREET IS '街道';
  27. COMMENT ON COLUMN T_ADDRESS.RESIDENTIAL IS '住宅区';
  28. COMMENT ON COLUMN T_ADDRESS.HOUSE_NUMBER IS '门牌号';
  29. CREATE TABLE T_ADDRESS_MORE
  30. (
  31. ACCOUNT_ID INTEGER NOT NULL,
  32. ADDRESS VARCHAR(200)
  33. );
  34. ALTER TABLE T_ADDRESS_MORE ADD FOREIGN KEY (ACCOUNT_ID) REFERENCES T_ADDRESS (ACCOUNT_ID) ON DELETE CASCADE ON UPDATE CASCADE;
  35. COMMENT ON TABLE T_ADDRESS_MORE IS '更多住址';
  36. COMMENT ON COLUMN T_ADDRESS_MORE.ACCOUNT_ID IS '所属地址';
  37. COMMENT ON COLUMN T_ADDRESS_MORE.ADDRESS IS '地址';
  38. CREATE TABLE T_PRODUCT
  39. (
  40. ID INTEGER NOT NULL,
  41. NAME VARCHAR(20) NOT NULL,
  42. PRICE NUMERIC(10,2) NOT NULL,
  43. PRIMARY KEY (ID)
  44. );
  45. COMMENT ON TABLE T_PRODUCT IS '商品';
  46. COMMENT ON COLUMN T_PRODUCT.NAME IS '商品名称';
  47. COMMENT ON COLUMN T_PRODUCT.PRICE IS '价格';
  48. CREATE TABLE T_ORDER
  49. (
  50. ID INTEGER NOT NULL,
  51. NAME VARCHAR(20) NOT NULL,
  52. ACCOUNT_ID INTEGER,
  53. DESCRIPTION VARCHAR(20) DEFAULT 'note',
  54. STAR_LEVEL INTEGER DEFAULT 1,
  55. CREATE_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  56. EDIT_TIME TIMESTAMP,
  57. PRIMARY KEY (ID)
  58. );
  59. ALTER TABLE T_ORDER ADD FOREIGN KEY (ACCOUNT_ID) REFERENCES T_ACCOUNT (ID);
  60. COMMENT ON TABLE T_ORDER IS '订单';
  61. COMMENT ON COLUMN T_ORDER.NAME IS '订单名称';
  62. COMMENT ON COLUMN T_ORDER.ACCOUNT_ID IS '所属帐号';
  63. COMMENT ON COLUMN T_ORDER.DESCRIPTION IS '描述';
  64. COMMENT ON COLUMN T_ORDER.STAR_LEVEL IS '星级';
  65. COMMENT ON COLUMN T_ORDER.CREATE_TIME IS '创建日期';
  66. COMMENT ON COLUMN T_ORDER.EDIT_TIME IS '编辑日期';
  67. CREATE TABLE T_ORDER_PRODUCTS
  68. (
  69. ORDER_ID INTEGER NOT NULL,
  70. PRODUCT_ID INTEGER NOT NULL
  71. );
  72. ALTER TABLE T_ORDER_PRODUCTS ADD FOREIGN KEY (ORDER_ID) REFERENCES T_ORDER (ID) ON DELETE CASCADE ON UPDATE CASCADE;
  73. ALTER TABLE T_ORDER_PRODUCTS ADD FOREIGN KEY (PRODUCT_ID) REFERENCES T_PRODUCT (ID) ON DELETE CASCADE ON UPDATE CASCADE;
  74. COMMENT ON TABLE T_ORDER_PRODUCTS IS '订单-商品';
  75. COMMENT ON COLUMN T_ORDER_PRODUCTS.ORDER_ID IS '订单';
  76. COMMENT ON COLUMN T_ORDER_PRODUCTS.PRODUCT_ID IS '商品';
  77. CREATE TABLE T_PRODUCT_PRICE_HISTORY
  78. (
  79. PRODUCT_ID INTEGER NOT NULL,
  80. PRICE NUMERIC(10,2) NOT NULL
  81. );
  82. ALTER TABLE T_PRODUCT_PRICE_HISTORY ADD FOREIGN KEY (PRODUCT_ID) REFERENCES T_PRODUCT (ID) ON DELETE CASCADE ON UPDATE CASCADE;
  83. COMMENT ON TABLE T_PRODUCT_PRICE_HISTORY IS '商品价格历史';
  84. COMMENT ON COLUMN T_PRODUCT_PRICE_HISTORY.PRODUCT_ID IS '商品';
  85. COMMENT ON COLUMN T_PRODUCT_PRICE_HISTORY.PRICE IS '价格';
  86. CREATE TABLE T_AUTO_GENERATED_KEYS
  87. (
  88. ID SERIAL PRIMARY KEY,
  89. NAME VARCHAR(20),
  90. CREATE_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP
  91. );
  92. CREATE TABLE T_DATE
  93. (
  94. ID INTEGER NOT NULL,
  95. "DATE" DATE,
  96. "TIME" TIME,
  97. "TIMESTAMP" TIMESTAMP,
  98. PRIMARY KEY (ID)
  99. );
  100. CREATE TABLE T_DATA_IMPORT
  101. (
  102. ID INTEGER NOT NULL,
  103. NAME VARCHAR(200),
  104. COL_DATE DATE,
  105. COL_TIME TIME,
  106. COL_TIMESTAMP TIMESTAMP,
  107. COL_BLOB BYTEA,
  108. COL_CLOB TEXT,
  109. PRIMARY KEY (ID)
  110. );
  111. CREATE TABLE T_DATA_EXPORT
  112. (
  113. ID INTEGER NOT NULL,
  114. NAME VARCHAR(200),
  115. COL_DATE DATE,
  116. COL_TIME TIME,
  117. COL_TIMESTAMP TIMESTAMP,
  118. COL_BLOB BYTEA,
  119. COL_CLOB TEXT,
  120. PRIMARY KEY (ID)
  121. );