July 24, 2007 at 1:14 pm
At first blush, it would seem that the database is not normalized. If it were, you would not need to store non-key fields in two tables. That's the ultimate solution, which is not feasible for the short term.
Question regarding business rules - IF you always enforce the content for all the different fields to match what is in the primary table, why don't you simply force ALL the content to be updated each time, regardless whether it changed?
Question regarding volumes - without trying to be nosy about the business being supported (convention registrations? memberships?), how is it that you have such a high volume of records to update - a 3000:1 ratio of parent/child records?
July 24, 2007 at 1:42 pm
First, be aware that "IF UPDATE(column)" is true when the column is being set and not that the value of the column is changed.
With this SQL, which changes no values:
Update Foo set fooColumn = fooColumn
IF UPDATE(fooColumn) will return true.
Try this as an alternative:
CREATE TRIGGER tU_MCParty ON MCParty FOR UPDATE
AS
-- Begin tran not need because triggers always run in a transaction.
set nocount on
set xact_abort on
-- when zero rows are affected, exit
IF 0 = (select count(*) from inserted) return
UPDATE DCParty
SET DCParty.ParticipationPercent = inserted.ParticipationPercent
,DCParty.MPFBankInd = inserted.ParticipationTypeInd
,DCParty.LastUpdatedDate = inserted.LastUpdatedDate
,DCParty.LastUpdatedTime = inserted.LastUpdatedTime
,DCParty.LastUpdatedComments = inserted.LastUpdatedComments
,DCParty.LastUpdatedBy = inserted.LastUpdatedBy
,DCParty.OrgKey = inserted.OrgKEY
,DCParty.ContactKey = inserted.ContactKey
FROM inserted
joindeleted
on inserted.MCPartyKEY= deleted.MCPartyKEY
joinDeliveryCommitment
on DeliveryCommitment.MasterCommitmentKEY = inserted.MasterCommitmentKEY
whereRoleKEY is NOT NULL
ANDDCParty.DeliveryCommitmentKEY = DeliveryCommitment.DeliveryCommitmentKEY
AND DCParty.RoleKEY = inserted.RoleKEY
-- any column has changed values
AND( inserted.ParticipationTypeInd deleted.ParticipationTypeInd
OR inserted.LastUpdatedDate deleted.LastUpdatedDate
OR inserted.LastUpdatedTime deleted.LastUpdatedTime
OR inserted.LastUpdatedComments deleted.LastUpdatedComments
OR inserted.LastUpdatedBy deleted.LastUpdatedBy
OR inserted.OrgKEY deleted.OrgKEY
OR inserted.ContactKey deleted.ContactKey
)
go
SQL = Scarcely Qualifies as a Language
July 24, 2007 at 6:25 pm
The other thing about Carl's trigger, is that it will actually update more than 1 row in the DCParty table whereas the original trigger would only update one row in the DCParty table no matter how many rows were updated in the MCParty table.
There's a way to speed up even Carl's trigger, a bit... instead of doing this...
CREATE TRIGGER tU_MCParty ON MCParty FOR UPDATE
AS
-- Begin tran not need because triggers always run in a transaction.
set nocount on
set xact_abort on
-- when zero rows are affected, exit
IF 0 = (select count(*) from inserted) return
... you can do this...
CREATE TRIGGER tU_MCParty ON MCParty FOR UPDATE
AS
-- Begin tran not need because triggers always run in a transaction.
set nocount on
set xact_abort on
-- when zero rows are affected, exit
IF @@ROWCOUNT = 0 return
Yes, Virginia, there is a Santa Clause
--Jeff Moden
Change is inevitable... Change for the better is not.
July 25, 2007 at 7:15 am
Thanks for your help guys..
This did not help me. The timeout error still persists.
Is ther any other way to enhance the performance of the execution of the Triggers.
- thanks
Sharan
July 25, 2007 at 7:24 am
Please post the execution plan. And the table DDL if that has not been posted yet.
July 25, 2007 at 2:15 pm
I believe you did not even try my suggestion.
You cannot achieve anything while you stick with loops.
_____________
Code for TallyGenerator
July 26, 2007 at 7:17 am
That is likely, however maybe the problem was much bigger than we anticipated.
Viewing 7 posts - 16 through 21 (of 21 total)
You must be logged in to reply to this topic. Login to reply