Advertisement
horozov86

10. Online Store

Oct 3rd, 2023
865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. CREATE TABLE item_types (
  2.     id SERIAL PRIMARY KEY,
  3.     item_type_name VARCHAR(50)
  4. );
  5.  
  6. CREATE TABLE items (
  7.     id SERIAL PRIMARY KEY,
  8.     item_name VARCHAR(50),
  9.     item_type_id INT,
  10.  
  11.     CONSTRAINT fk_items_item_types
  12.     FOREIGN KEY (item_type_id)
  13.     REFERENCES item_types(id)
  14. );
  15.  
  16. CREATE TABLE cities (
  17.     id SERIAL PRIMARY KEY,
  18.     city_name VARCHAR(50)
  19. );
  20.  
  21. CREATE TABLE customers (
  22.     id SERIAL PRIMARY KEY,
  23.     customer_name VARCHAR(100),
  24.     birthday DATE,
  25.     city_id INT,
  26.  
  27.     CONSTRAINT fk_customers_cities
  28.     FOREIGN KEY (city_id)
  29.     REFERENCES cities(id)
  30. );
  31.  
  32. CREATE TABLE orders (
  33.     id SERIAL PRIMARY KEY,
  34.     customer_id INT,
  35.  
  36.     CONSTRAINT fk_orders_customers
  37.     FOREIGN KEY (customer_id)
  38.     REFERENCES customers(id)
  39. );
  40.  
  41. CREATE TABLE order_items (
  42.     order_id INT,
  43.     item_id INT,
  44.  
  45.     CONSTRAINT pk_order_items
  46.     PRIMARY KEY (order_id, item_id),
  47.  
  48.     CONSTRAINT fk_order_items_orders
  49.     FOREIGN KEY (order_id)
  50.     REFERENCES orders(id),
  51.  
  52.     CONSTRAINT fk_order_items_items
  53.     FOREIGN KEY (item_id)
  54.     REFERENCES items(id)
  55.    
  56. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement