Advertisement
Guest User

Untitled

a guest
May 17th, 2019
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.00 KB | None | 0 0
  1. CREATE TABLE clients
  2. (
  3.     id BIGINT AUTO_INCREMENT
  4.         PRIMARY KEY,
  5.     first_name VARCHAR(32) NOT NULL,
  6.     last_name VARCHAR(32) NOT NULL
  7. );
  8.  
  9. CREATE TABLE items
  10. (
  11.     id BIGINT AUTO_INCREMENT
  12.         PRIMARY KEY,
  13.     name VARCHAR(32) NOT NULL,
  14.     price_currency VARCHAR(3) NOT NULL,
  15.     price_amount DECIMAL(7,2) NOT NULL
  16. );
  17.  
  18. CREATE TABLE orders
  19. (
  20.     id BIGINT AUTO_INCREMENT
  21.         PRIMARY KEY,
  22.     address_building VARCHAR(32) NOT NULL,
  23.     address_city VARCHAR(32) NOT NULL,
  24.     address_street VARCHAR(32) NOT NULL,
  25.     created datetime(6) NOT NULL,
  26.     express INT NOT NULL,
  27.     STATUS VARCHAR(1) NOT NULL,
  28.     client_id BIGINT NOT NULL,
  29.     CONSTRAINT orders2client_fk
  30.         FOREIGN KEY (client_id) REFERENCES clients (id)
  31. );
  32.  
  33. CREATE TABLE order_items
  34. (
  35.     order_id BIGINT NOT NULL,
  36.     quantity INT NOT NULL,
  37.     item_id BIGINT NOT NULL,
  38.     PRIMARY KEY (order_id, item_id),
  39.     CONSTRAINT order_items2item_fk
  40.         FOREIGN KEY (item_id) REFERENCES items (id),
  41.     CONSTRAINT order_items2order_fk
  42.         FOREIGN KEY (order_id) REFERENCES orders (id)
  43. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement