Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --1
- create trigger first_task
- on Company
- instead of delete
- as
- delete Department
- from deleted
- where deleted.Company_id = Department.Company_id
- delete Department_head
- from deleted
- join Department on Department.Company_id=deleted.Company_id
- join Department_head on Department_head.Dept_head_id = Department.Dept_head_id
- delete Company
- from deleted
- where Company.Company_id=deleted.Company_id
- --2
- alter trigger second_task
- on Evaluation
- instead of insert
- as
- declare @Id int
- declare @Last_date date
- begin
- select @Id = Cooperator_id
- from inserted
- select @Last_date = Date
- from Evaluation
- where Evaluation.Cooperator_id = @Id
- if(select DATEDIFF(WEEK,@Last_date, Date)from inserted) <> 0
- insert into Evaluation
- select Cooperator_id, Status, Date
- from inserted
- else
- print 'Между аттестациями не прошло недели'
- end
- insert into Evaluation
- values('2',5,'15/10/2023')
- --3
- create table Department_cooperator(
- Dept_Cop_id int primary key,
- Dept_id int,
- Number_cooperator smallint = exec count_Dept_coop Dept_id,
- constraint FK_Dept_id_Dept_coop foreign key(Dept_id)
- references Department(Dept_id)
- )
- drop table Department_cooperator
- alter table Department_cooperator
- Number_cooperator smallint = exec count_Dept_coop
- drop table Department_cooperator
- create trigger count_Dept_coop
- on Department_cooperator
- instead of insert
- as
- declare @Dep_id int
- begin
- select Dept_id = @Dep_id
- from inserted
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement