Sunday, March 25, 2012

Default Date Value (today)

I have migrated from Access to SQL Server.
In Access I have default date value of today's date.

In SQL Server, it is empty (after migration).
What is the corresponding syntax (value) to default to
the current Date & Time in a DATETIME Field (using Design Table) ?

Thanks you.

Also, what is the difference between DATETIME and SMALLDATETIME
fields ?

Pierre.Hey there,

When creating your table add a default constraint to your column, something like...

create table a_tbl (
col1 int not null,
col2 datetime constraint constr_1 default(getdate())
)

Or if you were creating the table using the table disign GUI, the default value should be getdate().

As for the difference between datetiem and smalldatetime, there is plenty of info in BOL. But basically smalldatetime is rounded to the nearest mintue, where as datetime is detailed to the fraction of a secound.

Hope this helps.

Originally posted by Plarde
I have migrated from Access to SQL Server.
In Access I have default date value of today's date.

In SQL Server, it is empty (after migration).
What is the corresponding syntax (value) to default to
the current Date & Time in a DATETIME Field (using Design Table) ?

Thanks you.

Also, what is the difference between DATETIME and SMALLDATETIME
fields ?

Pierre.|||As referred books online is the best bet to startwith the differences, syntax information and other examples which will give strength to the current knowledge in SQL server and ofcourse this forum is available to help you out in any consequences.

Good luck.

No comments:

Post a Comment