deyanmalinov

02-mysql

Sep 19th, 2020 (edited)
86
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE TABLE `minions` (
  2.   `id` INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
  3.   `name` VARCHAR(45) NULL,
  4.   `age` INT NULL
  5. );
  6.  
  7. CREATE TABLE `towns` (
  8.   `town_id` INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
  9.   `name` VARCHAR(45) NULL
  10. );
  11.  
  12. ALTER TABLE `minions`
  13. ADD COLUMN `town_id` INT NULL;
  14. ADD CONSTRAINT `fk_minions_towns`
  15.   FOREIGN KEY (`town_id`)
  16.   REFERENCES `towns` (`id`);
  17.  
  18. INSERT INTO `minions` (`id`, `name`, `age`, `town_id`)
  19. VALUES
  20. ('1', 'Kevin', '22', '1'),
  21. ('2', 'Bob', '15', '3'),
  22. ('3', 'Steward', null, '2');
  23.  
  24. INSERT INTO `towns` (`id`, `name`)
  25. VALUES
  26. ('1', 'Sofia'),
  27. ('2', 'Plovdiv'),
  28. ('3', 'Varna');  
  29.  
  30. TRUNCATE `minions`;
  31.  
  32. DROP TABLE `minions`, `towns`;
  33. ----------------------------------------
  34. CREATE SCHEMA `people` ;
  35.  
  36.  
RAW Paste Data