title: How do I prevent a database trigger from recursing?
body: <p>I've got the following trigger on a table for a SQL Server 2008 database. It's recursing, so I need to stop it.</p>
  
  <p>After I insert or update a record, I'm trying to simply update a single field on that table. </p>
  
  <p>Here's the trigger :</p>
  
  <pre><code>ALTER TRIGGER [dbo].[tblMediaAfterInsertOrUpdate] 
     ON  [dbo].[tblMedia]
     BEFORE INSERT, UPDATE
  AS 
  BEGIN
      SET NOCOUNT ON
  
      DECLARE @IdMedia INTEGER,
          @NewSubject NVARCHAR(200)   
  
      SELECT @IdMedia = IdMedia, @NewSubject = Title
      FROM INSERTED
  
      -- Now update the unique subject field.
      -- NOTE: dbo.CreateUniqueSubject is my own function. 
      --       It just does some string manipulation.
      UPDATE tblMedia
      SET UniqueTitle = dbo.CreateUniqueSubject(@NewSubject) + 
                        CAST((IdMedia) AS VARCHAR(10))
      WHERE tblMedia.IdMedia = @IdMedia
  END
  </code></pre>
  
  <p>Can anyone tell me how I can prevent the trigger's insert from kicking off another trigger again?</p>