SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Case of the Mysterious Missing Trigger
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

BobRoberts
Yak Posting Veteran

USA
97 Posts

Posted - 07/27/2012 :  12:02:28  Show Profile  Reply with Quote
I ran a command that deleted rows from table A. I discovered that in doing so rows from table B were also deleted.

Some pertinent facts:

1. Table A has no triggers.

2. I dropped or deleted all 3 triggers from table B.

3. Table A primary key is of type uniqueidentifier.

4. Table B has a foreign key matching the primary key of table A.

So what explains the deletion of rows from B when rows are deleted from A, and how do I temporarily suppress that happening?


yosiasz
Flowing Fount of Yak Knowledge

USA
1608 Posts

Posted - 07/27/2012 :  12:11:44  Show Profile  Click to see yosiasz's MSN Messenger address  Reply with Quote
what command did you run to delete rows from table A?
is there a clean up sql job?

<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47023 Posts

Posted - 07/27/2012 :  12:18:02  Show Profile  Reply with Quote
table B had a on delete cascade specified on foreign key constraint i think

you need to drop and recreate the fk without cascading option for avoiding this

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

BobRoberts
Yak Posting Veteran

USA
97 Posts

Posted - 07/27/2012 :  13:16:34  Show Profile  Reply with Quote
Yes, that turned out to be the magical secret. I scripted the foreign key as DROP To and CREATE To, then ran the DROP To script. I assume that running the CREATE To script will set everything back to what it was, as if it had never been dropped.

Thanks.


quote:
Originally posted by visakh16

table B had a on delete cascade specified on foreign key constraint i think

you need to drop and recreate the fk without cascading option for avoiding this

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47023 Posts

Posted - 07/27/2012 :  15:22:26  Show Profile  Reply with Quote
quote:
Originally posted by BobRoberts

Yes, that turned out to be the magical secret. I scripted the foreign key as DROP To and CREATE To, then ran the DROP To script. I assume that running the CREATE To script will set everything back to what it was, as if it had never been dropped.

Thanks.


quote:
Originally posted by visakh16

table B had a on delete cascade specified on foreign key constraint i think

you need to drop and recreate the fk without cascading option for avoiding this

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/






make sure you remove ON DELETE clause before you create it again

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Transact Charlie
Flowing Fount of Yak Knowledge

United Kingdom
3425 Posts

Posted - 07/28/2012 :  13:34:37  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
erm.. Why is it a problem at all?

If the second table had a constraint specified with an ON DELETE CASCADE then this *was the desired behaviour*

If you change this you won't be able to delete from tableA before removing the relevant rows in tableB (because to do so would invalidate the key constraint....)

So are you sure you actually have a problem here?

Transact Charlie
Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
http://nosqlsolution.blogspot.co.uk/
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000