User Id :    Password :      New Member   Forgot Password  
How to set default value to a column in a table in sql server
Description Here I will explain how you can set a default value to a column in an table in sql server.   No. of Views     2889
  Rating     0
Author Najmul Hoda   Posted On     27 Feb 2014

Sample Code   Download Code


Sometime we need to set a default value to a column in a table if we do not explicitly give any value to the column. Ex. If an employee joins a company then he should be assigned a default Project say "Not on project(NOP)" then in this case we can use a default value "Not on project(NOP)" in the project column of tblEmployee. We need not to explicitly give the project name for this employee record, default value will be automatically assigned if no value is provided for this column.



ALTER TABLE table_name
ALTER COLUMN column_name SET DEFALUT 'default_value'


ALTER TABLE tblEmployee 
ALTER COLUMN project SET DEFALUT 'Not on project(NOP)'

About Author

About Author He is a team lead, having 8+ years of experience. He loves writing technical article for .Net developers. Najmul Hoda
No Photo
Country United States
Company BirlaSoft
Home Page

Rate this article

Rating options from poor, fair, good, very good to excelent.  


Write your comment here.
Verification Code