Database (Trigger)

Source: Internet
Author: User

-----------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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.