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