How to set default value to a column in a table in sql server
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.
Syntax:
ALTER TABLE table_name
ALTER COLUMN column_name SET DEFALUT 'default_value'
ALTER TABLE tblEmployee
ALTER COLUMN project SET DEFALUT 'Not on project(NOP)'