-----------Trigger
--triggers are essentially a stored procedure
--Just not by exec to invoke execution, but by adding additions and deletions to the operation of the database to trigger execution
Select *from Student
Select *from Score
Alter TRIGGER Tr_student_delete
On student
--for delete--because the first execution inside of the outside of the first after the removal operation
Instead of delete--triggers are thrown when deleted, replacing the original operation with the action in the trigger
As
Delete from score where sno=108
--insert into student values (' 108 ', ' Peng Zeng ', ' Male ', ' 1997-7-5 ', ' 95033 ')
Delete from student where sno=108
Go
Delete from student where sno=108
Create Trigger Dongtaichufa
On teacher
Instead of delete--trigger trigger when deleted
As
Begin
DECLARE @tno varchar (20)
Set @tno = (select TNO from deleted)
Update teacher set Tname= ' Zhang San ' where [email protected]
End
Go
Delete from teacher where tno= ' 825 '
Select*from Teacher
Create Trigger Tr_teacher_insert
On teacher
For insert
As
Begin
DECLARE @tno varchar (20)
Set @tno = (select TNO from inserted)
Delete @sex varchar (20)
Set @aex = (select Tsex from teacher where [email protected])
If @sex = ' Male '
Update teacher set tsex= ' woman ' where [email protected]
Else
Update teacher set tsex= ' man ' where [email protected]
End
Go
Insert into teacher values (' 800 ', ' Harry ', ' Male ', ' 1990-09-09 ', ' Professor ', ' Computer Department ')
ALTER TABLE teacher Disable trigger all--Disable all triggers for the datasheet
ALTER TABLE teacher enable trigger all--all triggers on the datasheet
Database (Trigger)