Advertisement
TukieEz

Why are you GAY?

Oct 20th, 2023
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.46 KB | None | 0 0
  1. --1
  2. create trigger first_task
  3. on Company
  4. instead of delete
  5. as
  6. delete Department
  7. from deleted
  8. where deleted.Company_id = Department.Company_id
  9. delete Department_head
  10. from deleted
  11. join Department on Department.Company_id=deleted.Company_id
  12.     join Department_head on Department_head.Dept_head_id = Department.Dept_head_id
  13. delete Company
  14. from deleted
  15. where Company.Company_id=deleted.Company_id
  16. --2
  17. alter trigger second_task
  18. on Evaluation
  19. instead of insert
  20. as
  21. declare @Id int
  22. declare @Last_date date
  23. begin
  24.     select @Id = Cooperator_id
  25.         from inserted
  26.     select @Last_date = Date
  27.         from Evaluation
  28.             where Evaluation.Cooperator_id = @Id
  29.     if(select DATEDIFF(WEEK,@Last_date, Date)from inserted) <> 0
  30.         insert into Evaluation
  31.         select Cooperator_id, Status, Date
  32.         from inserted
  33.     else
  34.         print 'Между аттестациями не прошло недели'
  35. end
  36.  
  37. insert into Evaluation
  38. values('2',5,'15/10/2023')
  39.  
  40. --3
  41. create table Department_cooperator(
  42.     Dept_Cop_id int primary key,
  43.     Dept_id int,
  44.     Number_cooperator smallint = exec count_Dept_coop Dept_id,
  45.     constraint FK_Dept_id_Dept_coop foreign key(Dept_id)
  46.     references Department(Dept_id)
  47. )
  48. drop table Department_cooperator
  49. alter table Department_cooperator
  50.     Number_cooperator smallint = exec count_Dept_coop
  51.  
  52. drop table Department_cooperator
  53.  
  54. create trigger count_Dept_coop
  55. on Department_cooperator
  56. instead of insert
  57. as
  58. declare @Dep_id int
  59. begin
  60.     select Dept_id = @Dep_id
  61.         from inserted
  62.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement