Q

Problem deleting records on table with trigger to delete other records

I'm not a DBA, just an ASP developer. I have a table, aUser, with a trigger called DelUser that forces a delete from several other tables when deleting a record from aUser. I need to delete record from aUser where the userid is NOT in another table ("indExport"). The table "Webuser" is one of the tables in the trigger. My SQL is:
 select count(userid) from Webuser where not exists (select * from aUser where Webuser.userid = aUser.userid AND aUser.remoteid = indExport.inum).
The query goes on forever, and after 30 minutes, I cancelled it. Question: should I delete records in the trigger-referenced tables before I delete them from aUser? I'm at a total loss here.

In general, yes, that is the best practice. As for the query you are running, you said it goes on forever. What part of it goes on forever? Why does it go on forever? How are the tables indexed? And to top that off, you have created a query with a cross product in it which is going to kill your SQL Server. You are creating a three way cross product to be exact between aUser, Webuser, and indExport.

 

For More Information

This was first published in June 2004
This Content Component encountered an error

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchBusinessAnalytics

SearchDataCenter

SearchDataManagement

SearchAWS

SearchOracle

SearchContentManagement

SearchWindowsServer

Close