Cloud Training (Online)




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
Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.