title: How to add default constraint with condition in Sql Server?
body: <p>I am using Sql Server 2014</p>
  
  <pre><code>CREATE TABLE [dbo].[Record](
      [RecordId] [int] IDENTITY(1,1) NOT NULL,
      [BookId] [int] NULL,
      [TopicId] [int] NULL,
      [BookName] [varchar](250) NULL,
      [TopicName] [varchar](250) NULL,
      [RecordPath] [varchar](250) NULL,
      [RecordName] [varchar](250) NULL,
      [DurationInSec] [float] NULL,
   CONSTRAINT [PK_Record] PRIMARY KEY CLUSTERED 
  (
      [RecordId] ASC
  )
  
  
  ALTER TABLE dbo.Record ADD CONSTRAINT DC_RecordPath DEFAULT
               (CASE WHEN BookId = 1 THEN 'path/to/1' ELSE RecordPath END) 
  </code></pre>
  
  <p>I want a default constraint with condition as above, but this is not permitted.
  Is there any workaround without using triggers? </p>
  
  <p><strong>Edit:</strong> Computed column is not working, because the column is filled by a few stored procedures.
  I have two conditions;</p>
  
  <ol>
  <li>If <code>BookId</code> is 1 then <code>RecordPath</code> is path 1</li>
  <li>Else for any <code>BookId</code>, <code>RecordPath</code> is <code>RecordPath</code> comes from stored procedure</li>
  </ol>