|
Home > Archive > microsoft.public.sqlserver.server > November 2002 > using an FK to prevent parental deletions
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
using an FK to prevent parental deletions
|
|
| Justin A. 2002-11-10, 2:23 pm |
| How would I use a Foreign Key to prevent deletions on the
parent table?
For example, I have an Orders table and an OrderCancels
table related by a FK on the iOrdID. When the app requests
to delete a record on the Orders table, I need to check
the OrderCancels table via the iOrdID FK for corresponding
records, and if there are, not delete the order.
| |
| Steve McLarnon 2002-11-10, 9:23 pm |
| Justin A. wrote:
> How would I use a Foreign Key to prevent deletions on the
> parent table?
>
> For example, I have an Orders table and an OrderCancels
> table related by a FK on the iOrdID. When the app requests
> to delete a record on the Orders table, I need to check
> the OrderCancels table via the iOrdID FK for corresponding
> records, and if there are, not delete the order.
Justin,
Having the Foreign Key declared will prevent the deletion of the parent
row if there are any child rows with the oIrdId. The database will raise
an error on the attempt to delete
Steve McLarnon
First Consulting Group
|
|
|
|
|