How do you add a Column with a Default value to an existing SQL Server Table

To add a column with a default value to an existing SQL Server Table use the following code (in the next example we will add an integer column with a default value '1'):

ALTER TABLE [Table_Name]
ADD Column_Name int NOT NULL
DEFAULT (1)

In the next example we will add a varchar column with a default value 'A':

ALTER TABLE [Table_Name]
ADD Column_Name varchar NOT NULL
DEFAULT ('A')

If the new column is nullable, all existing rows will have NULL value in the new column. Rows added after you create the column will have the defined default value.

If the post helped you, please share it:
Pin It

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">