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

When dealing with a relational database management system (RDBMS) like SQL Server, compatibility level is an important concept to understand....
In this blog post, let’s learn about the error message “49975 – Unable to load controller client certificate due to...
In this blog post, let’s learn about the error message “49973 – Cannot remove tempdb remote file to local tempdb...