Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
Passcode:
How to add default value to the column in SQL
2862 Views
Hints 
Alter query with default used to give default value to table column when row generated.In the following example, Date as default value added in the orderdate column.

Note: getdate() function used to get time of the machine in sql.
Syntax
alter table tableName add constraint constraintName
default columnValue for columnName;
Example
Using the ALTER TABLE  statement, add the current system date
and time as the default value to the orderdate column of the Orders table.

alter table Orders add constraint dk
default getdate() for Orderdate;
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details