Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
bcanonica
Starting Member
35 Posts |
Posted - 2009-12-17 : 08:27:37
|
This trigger works when the table is small, but crashes the database when the table is large. Any ideas why this would happen? SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- =============================================CREATE TRIGGER [dbo].[SetChildrenInactive] ON [dbo].[Contacts] AFTER INSERT, UPDATEAS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; UPDATE ProjectContacts SET DoNotContact=1 FROM ProjectContacts c INNER JOIN inserted i ON c.ContactID=i.ContactID INNER JOIN Projects p ON c.ProjectID=p.ProjectID WHERE (p.Authorized IS NULL OR p.Authorized=0) AND i.DoNotContact=1ENDGO |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2009-12-17 : 12:04:18
|
| What do you mean "it crashes the database"?Is projectID and ContactID indexed in both ProjectContacts and Projects?Why even do this at all? If the SELECT statements joined to contacts then you wouldn't need this trigger at all. Looks like you're duplicating the doNotcontact field to me... |
 |
|
|
bcanonica
Starting Member
35 Posts |
Posted - 2009-12-17 : 13:45:48
|
| Looks like a table deadlock. It locks the Contact table and you can't do query the table at all. I have to drop the trigger to get it working again. This trigger updates the contacts child records in the project contacts table. A one to many relationship. |
 |
|
|
|
|
|