title: How can I validate data before insert/update with SQL Server?
body: <p>I have a table defined like this</p>
  
  <pre><code>CREATE TABLE [dbo].[ObjectRelationClauses]
  (
      [Id] INT NOT NULL PRIMARY KEY IDENTITY, 
      [RelationId] INT NOT NULL, 
      [OperatorType] NVARCHAR(3) NOT NULL, 
      [LocalPropertyId] INT NOT NULL, 
      [ForeignPropertyId] INT NULL, 
      [ForeignValue] VARCHAR(255) NULL, 
      [ParentClauseId] INT NULL
  )
  </code></pre>
  
  <p>I need to be able to raise an error if the value of both <code>ForeignPropertyId</code> and <code>ForeignValue</code> columns both <code>null</code>, otherwise I want to perform the operation.</p>
  
  <p>Here is what I tried</p>
  
  <pre><code>CREATE TRIGGER [dbo].[Trigger_ObjectRelationClauses]
      ON [dbo].[ObjectRelationClauses]
      FOR INSERT, UPDATE
      AS
      BEGIN
          SET NoCount ON
          IF(ForeignPropertyId IS NULL AND ForeignValue IS NULL)
          BEGIN
             RAISERROR('Either ForeignPropertyId or ForeignValue must be provided to perform this action!')
          END
  
      END
  </code></pre>
  
  <p>but this gives me a syntax error. Perhaps, the way I am using <code>RAISERROR</code> is wrong.</p>
  
  <p>How can I correctly add a trigger to validate the data on <code>INSERT</code> and <code>UPDATE</code>?</p>