|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: 2 days ago @ 3:01 AM
Points: 83,
Visits: 320
|
|
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
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 4:15 PM
Points: 37,651,
Visits: 29,903
|
|
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 2008, MVP 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
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: 2 days ago @ 3:01 AM
Points: 83,
Visits: 320
|
|
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
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 4:15 PM
Points: 37,651,
Visits: 29,903
|
|
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 2008, MVP 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
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Tuesday, August 10, 2010 5:07 AM
Points: 2,732,
Visits: 23,078
|
|
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.
|
|
|
|