Re: setting foreign key to null when deleting primary key
From: Christiaan (none_at_nospam.com)
Date: 05/14/04
- Next message: Aaron Bertrand - MVP: "Re: Comparing dates"
- Previous message: JC: "How to query job history"
- In reply to: David Portas: "Re: setting foreign key to null when deleting primary key"
- Next in thread: David Portas: "Re: setting foreign key to null when deleting primary key"
- Reply: David Portas: "Re: setting foreign key to null when deleting primary key"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 14 May 2004 18:10:44 +0200
thanx for the reply,
however I was looking for something Celko suggested:
CREATE TABLE Foo
( ...
x INTEGER
REFERENCES Bar(x)
ON DELETE SET NULL,
..);
(so not deleting the record with the foreign key, but setting the value of
the foreign key field to null). But if I am not mistaken, Sqlserver doesn't
support this?
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@acm.org> schreef in bericht
news:kvWdnT52s6j2SzndRVn-jg@giganews.com...
> If child rows exist with the foreign key value of the parent then a delete
> of the parent row will fail unless you have the ON DELETE CASCADE option
> set.
>
> To verify their existence before deleting you would have to query the
child
> table. You could use an INSTEAD OF DELETE trigger to catch the DELETE if
you
> wish.
>
> --
> David Portas
> SQL Server MVP
> --
>
>
- Next message: Aaron Bertrand - MVP: "Re: Comparing dates"
- Previous message: JC: "How to query job history"
- In reply to: David Portas: "Re: setting foreign key to null when deleting primary key"
- Next in thread: David Portas: "Re: setting foreign key to null when deleting primary key"
- Reply: David Portas: "Re: setting foreign key to null when deleting primary key"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|