Advertisement
Ivelin_1936

1ва

Feb 22nd, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.24 KB | None | 0 0
  1. CREATE TABLE deposit_types(
  2. deposit_type_id INT PRIMARY KEY,
  3. name VARCHAR(20));
  4.  
  5. CREATE TABLE deposits(
  6. deposit_id INT PRIMARY KEY AUTO_INCREMENT,
  7. amount DECIMAL(10,2),
  8. start_date DATE,
  9. end_date DATE,
  10. deposit_type_id INT,
  11. customer_id INT,
  12. FOREIGN KEY (deposit_type_id) REFERENCES deposit_types(deposit_type_id),
  13. FOREIGN KEY (customer_id) REFERENCES customers(customer_id));
  14.  
  15. CREATE TABLE employees_deposits(
  16. employee_id INT,
  17. deposit_id INT,
  18. PRIMARY KEY (employee_id, deposit_id),
  19. FOREIGN KEY (employee_id) REFERENCES employees(employee_id),
  20. FOREIGN KEY (deposit_id) REFERENCES deposits(deposit_id));
  21.  
  22. CREATE TABLE credit_history(
  23. credit_history_id INT PRIMARY KEY,
  24. mark CHAR(1),
  25. start_date DATE,
  26. end_date DATE,
  27. customer_id INT,
  28. FOREIGN KEY (customer_id) REFERENCES customers(customer_id));
  29.  
  30. CREATE TABLE payments(
  31. payment_id INT PRIMARY KEY,
  32. `date` DATE,
  33. amount DECIMAL(10,2),
  34. loan_id INT,
  35. FOREIGN KEY(loan_id) REFERENCES loans(loan_id));
  36.  
  37. CREATE TABLE users(
  38. user_id INT PRIMARY KEY,
  39. user_name VARCHAR(20),
  40. `password` VARCHAR(20),
  41. customer_id INT UNIQUE,
  42. FOREIGN KEY(customer_id) REFERENCES customers(customer_id));
  43.  
  44. ALTER TABLE employees
  45. ADD manager_id INT,
  46. ADD FOREIGN KEY (manager_id) REFERENCES employees(employee_id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement