June 20, 2008 at 12:57 am
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
June 20, 2008 at 1:05 am
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
June 20, 2008 at 1:09 am
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
June 20, 2008 at 1:20 am
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
June 20, 2008 at 5:20 am
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.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply