.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

OpenID
Please login with either your OpenID above, or your details below.
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

[Captcha]Enter the code shown (prevents robots):

Live Comment Preview