Advertisement
peshopbs2

Untitled

Dec 14th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. CREATE TABLE `cities` (
  2. `city_id` int(11) NOT NULL AUTO_INCREMENT,
  3. `name` varchar(50) DEFAULT NULL,
  4. PRIMARY KEY (`city_id`)
  5. );
  6.  
  7. CREATE TABLE `customers` (
  8. `customer_id` int(11) NOT NULL AUTO_INCREMENT,
  9. `name` varchar(50) DEFAULT NULL,
  10. `birthday` date DEFAULT NULL,
  11. `city_id` int(11) DEFAULT NULL,
  12. PRIMARY KEY (`customer_id`),
  13. KEY `FK_CITY_idx` (`city_id`),
  14. CONSTRAINT `FK_CITY` FOREIGN KEY (`city_id`) REFERENCES `cities` (`city_id`)
  15. );
  16.  
  17. CREATE TABLE `item_types` (
  18. `item_type_id` int(11) NOT NULL AUTO_INCREMENT,
  19. `name` varchar(50) DEFAULT NULL,
  20. PRIMARY KEY (`item_type_id`)
  21. );
  22.  
  23. CREATE TABLE `items` (
  24. `item_id` int(11) NOT NULL AUTO_INCREMENT,
  25. `name` varchar(50) DEFAULT NULL,
  26. `item_type_id` int(11) DEFAULT NULL,
  27. PRIMARY KEY (`item_id`),
  28. KEY `FK_ITEM_TYPE_idx` (`item_type_id`),
  29. CONSTRAINT `FK_ITEM_TYPE` FOREIGN KEY (`item_type_id`) REFERENCES `item_types` (`item_type_id`)
  30. );
  31.  
  32. CREATE TABLE `order_items` (
  33. `order_id` int(11) NOT NULL,
  34. `item_id` int(11) NOT NULL,
  35. PRIMARY KEY (`order_id`,`item_id`),
  36. KEY `FK_ITEM_idx` (`item_id`),
  37. CONSTRAINT `FK_ITEM` FOREIGN KEY (`item_id`) REFERENCES `items` (`item_id`),
  38. CONSTRAINT `FK_ORDER_FK` FOREIGN KEY (`order_id`) REFERENCES `orders` (`order_id`)
  39. );
  40.  
  41. CREATE TABLE `orders` (
  42. `order_id` int(11) NOT NULL AUTO_INCREMENT,
  43. `customer_id` int(11) DEFAULT NULL,
  44. PRIMARY KEY (`order_id`),
  45. KEY `FK_ORDER_idx` (`customer_id`),
  46. CONSTRAINT `FK_ORDER` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`customer_id`)
  47. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement