Advertisement
Guest User

Untitled

a guest
May 30th, 2019
363
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 `manufacturers`(
  2. `manufacturer_id` INT PRIMARY KEY AUTO_INCREMENT,
  3. `name` VARCHAR(10) NOT NULL,
  4. `established_on` DATE NOT NULL
  5. );
  6.  
  7. CREATE TABLE `models`(
  8. `model_id` INT PRIMARY KEY UNIQUE NOT NULL,
  9. `name` VARCHAR(10) NOT NULL,
  10. `manufacturer_id` INT,
  11. CONSTRAINT `fk_models_manufacturers`
  12. FOREIGN KEY (`manufacturer_id`) REFERENCES `manufacturers`(`manufacturer_id`)
  13. );
  14.  
  15. INSERT INTO `manufacturers` (`manufacturer_id`, `name`, `established_on`)
  16. VALUES (1, 'BMW', '1916-03-01'),
  17. (2, 'Tesla', '2003-01-01'),
  18. (3, 'Lada', '1966-05-01');
  19.  
  20. INSERT INTO `models` (`model_id`, `name`, `manufacturer_id`)
  21. VALUES ('101', 'X1', 1),
  22. ('102', 'i6', 1),
  23. ('103', 'Model S', 2),
  24. ('104', 'Model X', 2),
  25. ('105', 'Model 3', 2),
  26. ('106', 'Nova', 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement