dbTalk Databases Forums  

Default Date Column

microsoft.public.sqlserver.clients microsoft.public.sqlserver.clients


Discuss Default Date Column in the microsoft.public.sqlserver.clients forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Manish Chauhan
 
Posts: n/a

Default Default Date Column - 01-19-2010 , 05:25 AM






How can I create a table where the primary key is the dateime datatype and
I'd like to default it to the current dateime on SQL Server 2005?

Reply With Quote
  #2  
Old   
John Elliot
 
Posts: n/a

Default Re: Default Date Column - 01-19-2010 , 09:47 AM






On 1/19/2010 5:25 AM, Manish Chauhan wrote:
Quote:
How can I create a table where the primary key is the dateime datatype and
I'd like to default it to the current dateime on SQL Server 2005?

Here is the create table statement.

CREATE TABLE MYTABLE(
dt Date default GetDate() primary key,
someThingElse varchar(100)
)


I do not recommend you make Date as your primary key - you will never be
able to insert records simultaneously.

JE

Reply With Quote
  #3  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Default Date Column - 01-19-2010 , 06:00 PM



Manish Chauhan (ManishChauhan (AT) discussions (DOT) microsoft.com) writes:
Quote:
How can I create a table where the primary key is the dateime datatype and
I'd like to default it to the current dateime on SQL Server 2005?
I don't know what you intend to use this table for, but a datetime
value will full time portion is not likely to be a choice for a primary
key. If you are modelling a point in time, keep in mind that datetime
has a resolution of 3.33 ms, so if events can happen close to each other,
there may be duplicates.

--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.