SQL Server 101 – How to add a column with a default value to existing table ?

There are times when you want to add an column with a default value to the existing table in SQL Server and you can easily do that with the DEFAULT keyword.

How to add a column with a default value to existing table in SQL Server ?

Assume that you want to add a column called “EmploymentStatusID” to the “Employee” table with the default value of 1. Below is the code that demonstrates how to do it.

ALTER TABLE Employee
ADD EmploymentStatusID int NOT NULL DEFAULT(1)
GO

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this blog post, let’s learn about the error message “1459 – An error occurred while accessing the database mirroring...
In this blog post, let’s learn about the error message “7937 – Columnstore index has one or more missing column...