title: 'invalid for creating a default constraint' error when trying to add a constraint to an existing table
body: <p>I want to add a default constraint using <code>ALTER TABLE</code> in SQL Server, but I received the below error message instead. </p>
  
  <blockquote>
    <p>Column 'StartDate' in table 'Register' is invalid for creating a
    default constraint.</p>
  </blockquote>
  
  <p>I know that I can declare a constraint when I create a table, but that isn't the situation I am in. I hope someone can help me ;)</p>
  
  <p>Here is my <code>alter</code> statement:</p>
  
  <pre><code>ALTER TABLE [dbo].[Register]
    ADD CONSTRAINT [Register_StartDate] DEFAULT (GETDATE()) FOR StartDate 
  </code></pre>
  
  <p>And this is my create table script:</p>
  
  <pre><code>CREATE TABLE [dbo].[Register]
    (
       [ID]        [INT] IDENTITY(1, 1) NOT NULL,
       /* ....*/
       [StartDate] [DATETIME] NULL
    ) 
  </code></pre>
  
  <p><strong>Edited: Fixed: I forgot that the [StartDate] field doesn't even exist in the table. My bad!</strong></p>