Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Maintaining the Database Performance Expand / Collapse
Author
Message
Posted Friday, June 20, 2008 12:57 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 10:49 PM
Points: 90, Visits: 388
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
Post #520387
Posted Friday, June 20, 2008 1:04 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 12:15 PM
Points: 43,017, Visits: 36,179
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

Post #520389
Posted Friday, June 20, 2008 1:09 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 10:49 PM
Points: 90, Visits: 388
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
Post #520392
Posted Friday, June 20, 2008 1:20 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 12:15 PM
Points: 43,017, Visits: 36,179
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

Post #520396
Posted Friday, June 20, 2008 5:20 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

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.
Post #520537
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse