SQL Sever Fifth lesson: Trigger knowledge.

Source: Internet
Author: User

--triggers: Triggers are a special kind of stored procedure--The special place is that triggers are triggered by the operation of the database table.--stored procedures are performed by man -made execSelect * fromStudentCreate TriggerStudent_insert--Create a trigger onStudent--Specify the table where the trigger residesAfterInsert --triggers are automatically executed when an insert operation is performed, for and after are executed after the operation as    UpdateStudentSetSbirthdy='1999-9-9' whereSno=1GoInsert  intoStudentValues(7,'Shangli','male','1989-2-22',95031)Create TriggerStudent_delete onStudentinstead of Delete --replace an action with the procedure of a trigger to replace the deleted action, no longer able to delete the Stduent table data as    UpdateStudentSetSbirthdy= '2015-4-29' whereSno= 2GoDelete  fromStudentSelect* fromStudentDrop TriggerStudent_delete-----------------------------Trigger FormatCreate TriggerTrigger Name onTable name ( for/After|instead ofActionInsert|Update|Delete) asStored Procedure ContentGo for/After : Perform the action before executing the trigger instead of: Direct Replace operation--Create TriggerStudent_delete2 onStudentinstead of Delete   --Replace the delete from student operation directly as    Delete  fromScorewhereSno= 2    Delete  fromStudentwhereSno= 2   --There are primary foreign key relationships that can execute two of tablesGoDelete  fromStudentDrop TriggerStudent_delete2--Delete TriggerSelect* fromStudentSelect* fromscore--temp table in trigger: deleted,insertedDelete  fromCoursewhereCno='3-245'Create TriggerCourse_delete--to create a stored procedure onCourse--in the course tableinstead of Delete      --Replace the delete operation directly as    Select * fromDeleted--This is a temporary table. After replacing the operation, the data that you want to delete is stored in it .GoDelete  fromCoursewhereCno='3-245'--deleted is a temporary table that contains the data you want to delete,

SQL Sever Fifth lesson: Trigger knowledge.

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.