title: INSERT TRIGGER IF EXISTS
body: <p>I have looked through many articles and questions on here regarding this type of trigger but can't seem to find the exact answer.</p>
  
  <p>Hopefully its a very quick one, or me being silly...</p>
  
  <p>I have this:</p>
  
  <pre><code>ALTER TRIGGER [dbo].[JobCategoriesInsertTrigger]
  ON [dbo].[JobCategories]
  FOR INSERT
  AS
      IF EXISTS(SELECT [name], [areaId] FROM JobCategories WHERE [name] = (SELECT [name] FROM inserted) AND [areaId] = (SELECT [areaid] FROM inserted))
      BEGIN
        RAISERROR('THIS RECORD ALREADY EXISTS', 10, 1)
        PRINT 'The record you are trying to insert already exists'
        ROLLBACK
      END
  </code></pre>
  
  <p>I get the following when trying a non-existing insert:</p>
  
  <pre><code>THIS RECORD ALREADY EXISTS
  The record you are trying to insert already exists
  Msg 3609, Level 16, State 1, Line 4
  The transaction ended in the trigger. The batch has been aborted.
  </code></pre>
  
  <p>My question is, where have I gone wrong? - the name and areaid DO NOT, exist in the insert I am trying but I get stopped, have I done something a little backwards there?</p>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p>EDIT: </p>
  
  <p>Here is my Insert:</p>
  
  <pre><code>INSERT INTO [dbo].[JobCategories]
             ([id]
             ,[name]
             ,[description]
             ,[areaId]
             ,[enabled])
       VALUES
             (NEWID(),
             'test01',
             'testitem',
             '2C6F2293-2BBD-4E54-9709-FB9C4C0200F55',
             1)
  GO
  </code></pre>
  
  <p>Example of data already in the table:</p>
  
  <pre><code>id                                     name    description      areaId
  D120B34D-8074-4EA1-A52D-9477C3A9DFAF    500    STAT12 EXCEPTION 954A8859-311A-4F86-80CD-4E6DC4E5103E
  4B737203-6E6D-435B-9BAD-95C3B28DCCB1    501    STATIC EXCEPTION 954A8859-311A-4F86-80CD-4E6DC4E5103E
  A653FADC-996B-4E6F-80F4-5C08202228E2    551    EXCEPTION 70     954A8859-311A-4F86-80CD-4E6DC4E5103E
  </code></pre>