Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. CREATE TABLE items (
  2. id integer AUTO_INCREMENT,
  3. name varchar(255) NOT NULL,
  4. price int unsigned NOT NULL,
  5. PRIMARY KEY (id)
  6. )
  7.  
  8. CREATE TABLE companies (
  9. id integer AUTO_INCREMENT,
  10. name varchar(255) NOT NULL,
  11. address varchar(255) NOT NULL,
  12. PRIMARY KEY (id)
  13. )
  14.  
  15. CREATE TABLE orders (
  16. id integer AUTO_INCREMENT,
  17. date date NOT NULL,
  18. company_id integer NOT NULL,
  19.  
  20. PRIMARY KEY (id),
  21. INDEX (company_id),
  22. FOREIGN KEY(company_id)
  23. REFERENCES companies(id)
  24. )
  25.  
  26. CREATE TABLE order_details (
  27. order_id integer NOT NULL,
  28. item_id integer NOT NULL,
  29. number integer unsigned NOT NULL,
  30.  
  31. PRIMARY KEY (order_id, item_id),
  32.  
  33. FOREIGN KEY(order_id)
  34. REFERENCES orders(id)
  35. ON DELETE CASCADE,
  36.  
  37. FOREIGN KEY(item_id)
  38. REFERENCES items(id)
  39. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement