SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Maintaining the Database Performance


Maintaining the Database Performance

Author
Message
sram24_mca
sram24_mca
SSC Veteran
SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)

Group: General Forum Members
Points: 210 Visits: 508
Hi Guys,
We have the database triggers for audit trial,now we are facing performance problem because of those triggers.

How to monitor the Database Performance on sqlserver 2005 if the database will have the triggers


Tell me,how to increase the database performance with triggers


Thnx,
Ram
GilaMonster
GilaMonster
SSC Guru
SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)

Group: General Forum Members
Points: 86420 Visits: 45233
Could you post an example of one of those triggers please? It's hard to talk about increasing performance without some code.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


sram24_mca
sram24_mca
SSC Veteran
SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)

Group: General Forum Members
Points: 210 Visits: 508
ALTER TRIGGER [dbo].[Tg_Update_Service]
ON [dbo].[Table_name]
AFTER UPDATE
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @ServiceLogID NVARCHAR(50)
DECLARE @ServiceID NVARCHAR(30)
DECLARE @Name NVARCHAR(100)
DECLARE @Deleted BIT
DECLARE @LocationID NVARCHAR(30)
DECLARE @ModifiedDt DATETIME
DECLARE @ModifiedBy VARCHAR(50)

SELECT @ServiceID = I.ServiceID, @Name = I.[Name],
@LocationID = I.LocationID, @ModifiedBy = I.CreatedBy,
@Deleted = I.Deleted
FROM INSERTED I

EXEC Procedure_Name,'Table_Name', @LocationID, @ServiceLogID OUT
SET @ModifiedDt = GETDATE()

IF (@DELETED = 0)
BEGIN
INSERT INTO Table_Name(ServiceLogID, ServiceID, [Name], Deleted,
LocationID, ModifiedDt, ModifiedBy)
VALUES (@ServiceLogID, @ServiceID, @Name, @Deleted, @LocationID,
@ModifiedDt, @ModifiedBy)
END
ELSE
BEGIN
SET @ModifiedBy = @ModifiedBy + '/Deleted'
INSERT INTO Table_Name(ServiceLogID, ServiceID, [Name], Deleted,
LocationID, ModifiedDt, ModifiedBy)
VALUES (@ServiceLogID, @ServiceID, @Name, @Deleted, @LocationID,
@ModifiedDt, @ModifiedBy)
END
END
GilaMonster
GilaMonster
SSC Guru
SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)

Group: General Forum Members
Points: 86420 Visits: 45233
sram24_mca (6/20/2008)

SELECT   @ServiceID = I.ServiceID, @Name = I.[Name], 
@LocationID = I.LocationID, @ModifiedBy = I.CreatedBy,
@Deleted = I.Deleted
FROM INSERTED I





One problem with your trigger straight off, ignoring performance problems...
It only caters for single row updates.

The inserted table contains all the rows affected by the update. If the update affects more than 1 row, then your select there will return the values for 1 row. No guarentees which one.

On the performance side, what problems are you seeing?

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Michael Earl-395764
Michael Earl-395764
SSCarpal Tunnel
SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)

Group: General Forum Members
Points: 4865 Visits: 23078
There is a procedure call to get some kind of ServiceLogID returned. So, this procedure is being called for every update made in your database, what is it doing?


Since this trigger is only able to handle single-row updates, I would suspect much of the code in the database was designed in the same RBAR fashion. It is pretty likely that your performance issues are not the result of the triggers so much as a result of programming that is in general conflict with what SQL Server handles well.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search