Powered by Blogger.

Saturday, February 15, 2014

Add default date to column in SQL Server 2008




In this post we will discuss how we can insert default datetime to a column in sql server 2008 in management studio as well as by using query.

In my previous posts we have discussed about Show confirmation message in gridview for delete in Asp.net, Add new column to existing table in sql server 2008 [Read here] and WCF tutorial and example in C#.Net.

As we know through the use of GETDATE() function we can get the current date time in SQL server 2008.

Below is the query to add default date value to a column.

CREATE TABLE Employees
(
EmpId int NOT NULL PRIMARY KEY,
Name varchar(50) NOT NULL,
JoiningDate datetime NOT NULL DEFAULT GETDATE()
)

Check the below figure to add default value using Management Studio.




0 comments

Post a Comment