Slow SQL Trigger

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RyanK
    New Member
    • Jul 2012
    • 1

    Slow SQL Trigger

    Issues with a SQL trigger, it takes 10 seconds to run and I cannot see why...please can you help:

    Code:
    USE [Sound]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER TRIGGER [dbo].[trSound_Changepath]
       ON  [dbo].[SoundFiles]
       AFTER INSERT
    AS
    BEGIN
    
        SET NOCOUNT ON;
    
        UPDATE s
        SET s.[SoundFile] = 'D:\Recordings' + substring(i.[SoundFile] , 40 , len(i.[SoundFile] ) - 26)
        FROM dbo.[SoundFiles] s
        JOIN inserted i
        ON s.[SoundFile] = i.[SoundFile]
        WHERE Left(i.[SoundFile],2) = 'C:'
        AND i.[SoundFile] <> 'c:\M2.encrypt'
    
    
    END
    Last edited by Rabbit; Jul 3 '12, 04:49 PM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code.

    Avoid functions on fields when possible. Instead of your left, use a like.

    Put an index on soundfile.

    That'll be about as fast as you can make it.

    Comment

    Working...