test-sql-script-sqlserver.sql 3.3 KB

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