In this case, in addition to enabling cascading modification and cascading deletion using the primary and foreign key constraints between two tables, we can also use triggers to accomplish similar functions. The following example shows how to delete a trigger:
Assume that a sysfuncdic (function dictionary table), sysfuncrights (function permission table), funcid in the function permission table, and funcid in the function dictionary table have foreign key constraints. Now we want to delete the records in sysfuncdic, it cannot be deleted because it has been used as a foreign key constraint. The solution is to delete all records corresponding to funcid in the sysfuncrights table.
Create Table sysfuncdic (funcid int not null identity (100) primary key, funcname varchar () Create Table sysfuncrights (ID int not null Primary Key Identity ), funcid int not null, empid int not null) insert into sysfuncdic values ('A') insert into sysfuncdic values ('bb') insert into sysfuncdic values ('cc ') insert into sysfuncrights values) /*********************** delete a trigger ************** * ***********/create trigger tri_delete on sysfuncdicinstead of deleteasbegin declare @ funcid int; select @ funcid = funcid from deleted; Delete sysfuncdic where funcid = @ funcid; Delete sysfuncrights where funcid = @ funcid; end /************************************** * ******************/select * From sysfuncdic; -- query function dictionary table record select * From sysfuncrights; -- query function permission Table Record Delete from sysfuncdic where funcid = 1; -- delete function dictionary table record for test