Advertisement
yani-valeva

Section 1: DDL

Jun 23rd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. CREATE TABLE `deposit_types` (
  2. `deposit_type_id` INT,
  3. `name` VARCHAR(20),
  4. CONSTRAINT `pk_deposit_types` PRIMARY KEY (`deposit_type_id`)
  5. );
  6.  
  7. CREATE TABLE `deposits` (
  8. `deposit_id` INT AUTO_INCREMENT,
  9. `amount` DECIMAL(10 , 2 ),
  10. `start_date` DATE,
  11. `end_date` DATE,
  12. `deposit_type_id` INT,
  13. `customer_id` INT,
  14. CONSTRAINT `pk_deposits` PRIMARY KEY (`deposit_id`),
  15. CONSTRAINT `fk__deposits_deposit_types` FOREIGN KEY (`deposit_type_id`)
  16. REFERENCES `deposit_types`(`deposit_type_id`),
  17. CONSTRAINT `fk_deposits_customers` FOREIGN KEY (`customer_id`)
  18. REFERENCES `customers`(`customer_id`)
  19. );
  20.  
  21. CREATE TABLE `employees_deposits` (
  22. `employee_id` INT,
  23. `deposit_id` INT,
  24. CONSTRAINT `pk_employees_deposits` PRIMARY KEY (`employee_id` , `deposit_id`),
  25. CONSTRAINT `fk_employees_deposits_employees` FOREIGN KEY (`employee_id`)
  26. REFERENCES `employees` (`employee_id`),
  27. CONSTRAINT `fk_employees_deposits_deposits` FOREIGN KEY (`deposit_id`)
  28. REFERENCES `deposits` (`deposit_id`)
  29. );
  30.  
  31. CREATE TABLE `credit_history` (
  32. `credit_history_id` INT,
  33. `mark` CHAR(1),
  34. `start_date` DATE,
  35. `end_date` DATE,
  36. `customer_id` INT,
  37. CONSTRAINT `pk_credit_history` PRIMARY KEY (`credit_history_id`),
  38. CONSTRAINT `fk_credit_history_customers` FOREIGN KEY (`customer_id`)
  39. REFERENCES `customers` (`customer_id`)
  40. );
  41.  
  42. CREATE TABLE `payments` (
  43. `payement_id` INT,
  44. `date` DATE,
  45. `amount` DECIMAL(10 , 2 ),
  46. `loan_id` INT,
  47. CONSTRAINT `pk_payments` PRIMARY KEY (`payement_id`),
  48. CONSTRAINT `fk_payments_loans` FOREIGN KEY (`loan_id`)
  49. REFERENCES `loans` (`loan_id`)
  50. );
  51.  
  52. CREATE TABLE `users` (
  53. `user_id` INT,
  54. `user_name` VARCHAR(20),
  55. `password` VARCHAR(20),
  56. `customer_id` INT UNIQUE,
  57. CONSTRAINT `pk_users` PRIMARY KEY (`user_id`),
  58. CONSTRAINT `fk_users_customers` FOREIGN KEY (`customer_id`)
  59. REFERENCES `customers` (`customer_id`)
  60. );
  61.  
  62.  
  63. ALTER TABLE `employees`
  64. ADD `manager_id` INT,
  65. ADD CONSTRAINT `fk_employees_employees` FOREIGN KEY(`manager_id`)
  66. REFERENCES `employees`(`employee_id`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement