test-sql-script-oracle.sql 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. CREATE TABLE T_ACCOUNT
  2. (
  3. ID INTEGER NOT NULL,
  4. NAME VARCHAR2(20) NOT NULL,
  5. HEAD_IMG BLOB,
  6. INTRODUCTION CLOB,
  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 VARCHAR2(50),
  17. STREET VARCHAR2(100),
  18. RESIDENTIAL VARCHAR2(100),
  19. HOUSE_NUMBER VARCHAR2(100)
  20. );
  21. ALTER TABLE T_ADDRESS ADD CONSTRAINT T_ADDRESS_FK_T_ACCOUNT FOREIGN KEY (ACCOUNT_ID) REFERENCES T_ACCOUNT (ID);
  22. ALTER TABLE T_ADDRESS ADD CONSTRAINT T_ADDRESS_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 VARCHAR2(200)
  33. );
  34. ALTER TABLE T_ADDRESS_MORE ADD CONSTRAINT T_ADDRESS_MORE_FK_T_ADDRESS FOREIGN KEY (ACCOUNT_ID) REFERENCES T_ADDRESS (ACCOUNT_ID) ON DELETE 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 VARCHAR2(20) NOT NULL,
  42. PRICE NUMBER(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 VARCHAR2(20) NOT NULL,
  52. ACCOUNT_ID INTEGER,
  53. DESCRIPTION VARCHAR2(20) DEFAULT 'note',
  54. STAR_LEVEL INTEGER DEFAULT 1,
  55. CREATE_TIME TIMESTAMP DEFAULT SYSDATE,
  56. EDIT_TIME TIMESTAMP,
  57. PRIMARY KEY (ID)
  58. );
  59. ALTER TABLE T_ORDER ADD CONSTRAINT T_ORDER_FK_T_ACCOUNT 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 CONSTRAINT T_ORDER_PRODUCTS_FK_T_ORDER FOREIGN KEY (ORDER_ID) REFERENCES T_ORDER (ID) ON DELETE CASCADE;
  73. ALTER TABLE T_ORDER_PRODUCTS ADD CONSTRAINT T_ORDER_PRODUCTS_FK_T_PRODUCT FOREIGN KEY (PRODUCT_ID) REFERENCES T_PRODUCT (ID) ON DELETE 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 NUMBER(10,2) NOT NULL
  81. );
  82. ALTER TABLE T_PRODUCT_PRICE_HISTORY ADD CONSTRAINT T_PPH_FK_T_PRODUCT FOREIGN KEY (PRODUCT_ID) REFERENCES T_PRODUCT (ID) ON DELETE 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 INTEGER NOT NULL,
  89. NAME VARCHAR2(20),
  90. CREATE_TIME TIMESTAMP DEFAULT SYSDATE,
  91. PRIMARY KEY (ID)
  92. );