title: SQL Server trigger with error message
body: <p>I have written a trigger which block duplicate records if found in two column.</p>
  
  <p>how can I throw the rows in message which is causing duplicate.
  I am trying to show those error rows in error message.</p>
  
  <p>Code:</p>
  
  <pre><code>CREATE TRIGGER [dbo].[BlockDuplicates]
   ON [dbo].[table]
   INSTEAD OF INSERT
  AS
  BEGIN
    SET NOCOUNT ON;
  
    IF NOT EXISTS (SELECT 1 FROM inserted AS i 
      INNER JOIN dbo.WSP_INPUT_ACTV AS t
      ON i.GoogleID = t.GoogleID
      AND i.SKU = t.SKU
  
       WHERE i.FleetID &lt;&gt; 008
    )
    BEGIN
      INSERT dbo.WSP_INPUT_ACTV (COL1,COL2,COL3)
        SELECT COL1,COL2,COL3 FROM inserted;
    END
    ELSE
    BEGIN
      PRINT 'INSERTION ABORTED';
    END
  END
  </code></pre>