Guest User

Soft_uni

a guest
Feb 1st, 2018
127
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE TABLE IF NOT EXISTS `towns`(
  2.     `id` INT AUTO_INCREMENT PRIMARY KEY,
  3.     `name` VARCHAR(50) NOT NULL
  4. );
  5.  
  6. CREATE TABLE IF NOT EXISTS `addresses`(
  7.     `id` INT AUTO_INCREMENT PRIMARY KEY,
  8.     `address_text` TEXT NOT NULL,
  9.     `town_id` INT
  10. );
  11.  
  12. ALTER TABLE `addresses`
  13.     ADD CONSTRAINT `FK_addresses_towns`
  14.     FOREIGN KEY (`town_id`) REFERENCES `towns`(`id`);
  15.  
  16. CREATE TABLE IF NOT EXISTS `departments`(
  17.     `id` INT AUTO_INCREMENT PRIMARY KEY,
  18.     `name` VARCHAR(50) NOT NULL
  19. );
  20.  
  21. CREATE TABLE IF NOT EXISTS `employees`(
  22.     `id` INT AUTO_INCREMENT PRIMARY KEY,
  23.     `first_name` VARCHAR(50) NOT NULL,
  24.     `middle_name` VARCHAR(50),
  25.     `last_name` VARCHAR(50) NOT NULL,
  26.     `job_title` VARCHAR(50) NOT NULL,
  27.     `department_id` INT,
  28.     `hire_date` DATETIME,
  29.     `salary` DECIMAL (6,2) NOT NULL,
  30.     `address_id` INT
  31. );
  32.  
  33. ALTER TABLE `employees`
  34.     ADD CONSTRAINT `FK_employees_departments`
  35.     FOREIGN KEY (`department_id`) REFERENCES `departments`(`id`),
  36.     ADD CONSTRAINT `FK_employees_addresses`
  37.     FOREIGN KEY (`address_id`) REFERENCES `addresses`(`id`);
RAW Paste Data