Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Cascade deletion


Message #1 by mahesh.kava@p... on Fri, 5 Jan 2001 13:26:54 -0000
Dear Michael

If you create a trigger on the table with the primary key you can then set
this up to delete the records from the other two tables.

Like:

CREATE TRIGGER trigger_name
ON table
[WITH ENCRYPTION]
{
    {FOR { [DELETE] [,] [INSERT] [,] [UPDATE] }
        [WITH APPEND]
        [NOT FOR REPLICATION]
        AS
            sql_statement [...n]
    }
    |
    {FOR { [INSERT] [,] [UPDATE] }
        [WITH APPEND]
        [NOT FOR REPLICATION]
        AS
        {    IF UPDATE (column)
            [{AND | OR} UPDATE (column)]
                [...n]
            | IF (COLUMNS_UPDATED() {bitwise_operator} updated_bitmask)
                { comparison_operator} column_bitmask [...n]
        }
            sql_statement [ ...n]
    }
}

Hope this helps
Regards Duncan

-----Original Message-----
From: Michael Morisoli [mailto:Michael@M...]
Sent: 05 January 2001 15:20
To: sql language
Subject: [sql_language] RE: Cascade deletion


To my knowledge, this feature did not exist in SQL Server until SQL
Server 2000.  It now fully supports cascading deletes...


-----Original Message-----
From: mahesh.kava@p...
[mailto:mahesh.kava@p...]
Sent: Friday, January 05, 2001 5:27 AM
To: sql language
Subject: [sql_language] Cascade deletion

hi all!
i have created 3 tables in sql server with a primary key (memid)set in
one
table.The field memid is the foreign key in the other 2 tables.
is there a way in which if i delete a row from the primary key table
the rows in the other two tables releted to the primary key gets deleted
as well,insted of writing seperate queries for deleting from the other 2
tables.
thanks
regds
mahesh




---
You are currently subscribed to sql_language as: $subst('Recip.EmailAddr')
To unsubscribe send a blank email to leave-sql_language-$subst('Recip.MemberIDChar')@p2p.wrox.com

  Return to Index