Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to define a default value for DATETIME column? 2

Status
Not open for further replies.

sjh

Programmer
Joined
Oct 29, 2001
Messages
263
Location
US
Hi,

I would like to assign a default value (i.e. current date time) to a DATETIME column in my table. What is the correct syntax for specifying that? In Oracle, I can use SYSDATE, but I don't know if that's possible in SQL Server database.

create table SESSION_INFO (
SESSION_KEY numeric identity,
USERID varchar(32) not null,
STARTED_ON datetime not null
}

Thank you in advance!
 
In Sql Server you use getdate(). You can define it in code or you can use Enterpise Manager to set the default.

Jim
 
create table SESSION_INFO (
SESSION_KEY numeric identity,
USERID varchar(32) not null,
STARTED_ON datetime not null default getdate()
)
insert into SESSION_INFO(USERID)
select 1

select * from SESSION_INFO

Denis The SQL Menace
SQL blog:
Personal Blog:
 
This will work for sure but Microsoft is recommending against using GETDATE() function and would like to see all programmers use CURRENT_TIMESTAMP.

Walid Magd

The primary challenge of every software development team is to engineer the illusion of simplicity in the face of essential complexity.
-Grady Booch
 
i tried in em to put CURRENT_TIMESTAMP as the default value and it reverts to (getdate())

so much for Microsoft
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top