Advertisement
IhorD

Shop DB

Jan 19th, 2024 (edited)
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 4.96 KB | None | 0 0
  1. https://ibb.co/Xbt0ySj
  2.  
  3. -- tables
  4. -- Table: Client
  5. CREATE TABLE Client (
  6.     ID INTEGER  NOT NULL,
  7.     Name VARCHAR2(30)  NOT NULL,
  8.     Surname VARCHAR2(40)  NOT NULL,
  9.     Discount INTEGER  NOT NULL,
  10.     CONSTRAINT Client_pk PRIMARY KEY (ID)
  11. ) ;
  12.  
  13. -- Table: Order
  14. CREATE TABLE ClientOrder (
  15.     ID INTEGER  NOT NULL,
  16.     CreatedDate DATE  NOT NULL,
  17.     Status_ID INTEGER  NOT NULL,
  18.     Client_ID INTEGER  NOT NULL,
  19.     CONSTRAINT Order_pk PRIMARY KEY (ID)
  20. ) ;
  21.  
  22. -- Table: Order_Product
  23. CREATE TABLE Order_Product (
  24.     ID INTEGER  NOT NULL,
  25.     Price NUMBER(4,2)  NOT NULL,
  26.     Amount INTEGER  NOT NULL,
  27.     Order_ID INTEGER  NOT NULL,
  28.     Product_ID INTEGER  NOT NULL,
  29.     CONSTRAINT Order_Product_pk PRIMARY KEY (ID)
  30. ) ;
  31.  
  32. -- Table: Product
  33. CREATE TABLE Product (
  34.     ID INTEGER  NOT NULL,
  35.     Name VARCHAR2(30)  NOT NULL,
  36.     CurrentAvailability INTEGER  NOT NULL,
  37.     CONSTRAINT Product_pk PRIMARY KEY (ID)
  38. ) ;
  39.  
  40. -- Table: Status
  41. CREATE TABLE Status (
  42.     ID INTEGER  NOT NULL,
  43.     Name VARCHAR2(30)  NOT NULL,
  44.     CONSTRAINT Status_pk PRIMARY KEY (ID)
  45. ) ;
  46.  
  47. -- foreign keys
  48. -- Reference: Order_Client (table: Order)
  49. ALTER TABLE ClientOrder ADD CONSTRAINT Order_Client
  50.     FOREIGN KEY (Client_ID)
  51.     REFERENCES Client (ID);
  52.  
  53. -- Reference: Order_Product_Order (table: Order_Product)
  54. ALTER TABLE Order_Product ADD CONSTRAINT Order_Product_Order
  55.     FOREIGN KEY (Order_ID)
  56.     REFERENCES ClientOrder (ID);
  57.  
  58. -- Reference: Order_Product_Product (table: Order_Product)
  59. ALTER TABLE Order_Product ADD CONSTRAINT Order_Product_Product
  60.     FOREIGN KEY (Product_ID)
  61.     REFERENCES Product (ID);
  62.  
  63. -- Reference: Order_Status (table: Order)
  64. ALTER TABLE ClientOrder ADD CONSTRAINT Order_Status
  65.     FOREIGN KEY (Status_ID)
  66.     REFERENCES Status (ID);
  67.  
  68.  
  69. --data
  70.  
  71. --Table: Client
  72.  
  73. INSERT INTO Client (ID, Name, Surname, Discount) VALUES (1, 'John', 'Doe', 10);
  74. INSERT INTO Client (ID, Name, Surname, Discount) VALUES (2, 'Jane', 'Smith', 5);
  75. INSERT INTO Client (ID, Name, Surname, Discount) VALUES (3, 'Michael', 'Johnson', 15);
  76. INSERT INTO Client (ID, Name, Surname, Discount) VALUES (4, 'Emily', 'Williams', 0);
  77. INSERT INTO Client (ID, Name, Surname, Discount) VALUES (5, 'David', 'Brown', 20);
  78.  
  79. --Table: Status
  80.  
  81. INSERT INTO Status (ID, Name) VALUES (1, 'Pending');
  82. INSERT INTO Status (ID, Name) VALUES (2, 'Processing');
  83. INSERT INTO Status (ID, Name) VALUES (3, 'Completed');
  84.  
  85. --Table: Order
  86.  
  87. INSERT INTO ClientOrder (ID, CreatedDate, Status_ID, Client_ID) VALUES (1, TO_DATE('2023-05-01', 'YYYY-MM-DD'), 1, 1);
  88. INSERT INTO ClientOrder (ID, CreatedDate, Status_ID, Client_ID) VALUES (2, TO_DATE('2023-05-03', 'YYYY-MM-DD'), 2, 2);
  89. INSERT INTO ClientOrder (ID, CreatedDate, Status_ID, Client_ID) VALUES (3, TO_DATE('2023-05-05', 'YYYY-MM-DD'), 1, 3);
  90. INSERT INTO ClientOrder (ID, CreatedDate, Status_ID, Client_ID) VALUES (4, TO_DATE('2023-05-08', 'YYYY-MM-DD'), 3, 4);
  91. INSERT INTO ClientOrder (ID, CreatedDate, Status_ID, Client_ID) VALUES (5, TO_DATE('2023-05-10', 'YYYY-MM-DD'), 2, 1);
  92.  
  93. --Table: Product
  94.  
  95. INSERT INTO Product (ID, Name, CurrentAvailability) VALUES (1, 'T-Shirt', 50);
  96. INSERT INTO Product (ID, Name, CurrentAvailability) VALUES (2, 'Jeans', 30);
  97. INSERT INTO Product (ID, Name, CurrentAvailability) VALUES (3, 'Dress', 20);
  98. INSERT INTO Product (ID, Name, CurrentAvailability) VALUES (4, 'Jacket', 15);
  99. INSERT INTO Product (ID, Name, CurrentAvailability) VALUES (5, 'Shoes', 25);
  100. INSERT INTO Product (ID, Name, CurrentAvailability) VALUES (6, 'Sweater', 10);
  101. INSERT INTO Product (ID, Name, CurrentAvailability) VALUES (7, 'Shorts', 20);
  102. INSERT INTO Product (ID, Name, CurrentAvailability) VALUES (8, 'Skirt', 15);
  103. INSERT INTO Product (ID, Name, CurrentAvailability) VALUES (9, 'Blouse', 12);
  104. INSERT INTO Product (ID, Name, CurrentAvailability) VALUES (10, 'Pants', 18);
  105.  
  106. --Table: Order_Product
  107.  
  108. INSERT INTO Order_Product (ID, Price, Amount, Order_ID, Product_ID) VALUES (1, 29.99, 2, 1, 3);
  109. INSERT INTO Order_Product (ID, Price, Amount, Order_ID, Product_ID) VALUES (2, 19.99, 1, 2, 1);
  110. INSERT INTO Order_Product (ID, Price, Amount, Order_ID, Product_ID) VALUES (3, 39.99, 1, 2, 4);
  111. INSERT INTO Order_Product (ID, Price, Amount, Order_ID, Product_ID) VALUES (4, 24.99, 3, 3, 2);
  112. INSERT INTO Order_Product (ID, Price, Amount, Order_ID, Product_ID) VALUES (5, 34.99, 2, 4, 5);
  113. INSERT INTO Order_Product (ID, Price, Amount, Order_ID, Product_ID) VALUES (6, 49.99, 1, 4, 3);
  114. INSERT INTO Order_Product (ID, Price, Amount, Order_ID, Product_ID) VALUES (7, 14.99, 2, 5, 6);
  115. INSERT INTO Order_Product (ID, Price, Amount, Order_ID, Product_ID) VALUES (8, 29.99, 1, 5, 9);
  116. INSERT INTO Order_Product (ID, Price, Amount, Order_ID, Product_ID) VALUES (9, 19.99, 1, 5, 7);
  117. INSERT INTO Order_Product (ID, Price, Amount, Order_ID, Product_ID) VALUES (10, 39.99, 1, 5, 10);
  118. INSERT INTO Order_Product (ID, Price, Amount, Order_ID, Product_ID) VALUES (11, 59.99, 2, 1, 4);
  119. INSERT INTO Order_Product (ID, Price, Amount, Order_ID, Product_ID) VALUES (12, 34.99, 1, 1, 6);
  120.  
  121.  
  122.  
  123.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement