.Net ramblings
# Wednesday, 16 May 2007
Sql Triggers for Dummies
i always found the syntax of SQL triggers very difficult to remember, so i'm just posting a sample one here.  it performs a cascade delete on a table that doesn't have referential integrity (because there are 2 potential foreign keys).
ALTER TRIGGER [dbo].[Table1CascadeDeleteTable2]
ON [dbo].[Table1]
FOR DELETE
AS
BEGIN
declare @Ref int;
SELECT @Ref = Ref FROM Deleted;
delete from Table2 where Ref = @Ref;
END


Wednesday, 16 May 2007 18:36:37 (GMT Daylight Time, UTC+01:00)  #    Comments [0]  Database