Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Current Date/Time

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2007-01-18 : 08:39:16
Brian writes "I need help inserting the "current" date and time into a table while creating a new row in an existing table. I want to write a dynamic bit of code that can be used over and over again on different days. Any thoughts?"

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-01-18 : 08:41:27
Why don't you attach getdate() as default to the date column?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-18 : 09:35:23
ALTER TABLE <YourTableNameHere>
ADD <YourColumnNameHere> AS GETDATE() WITH VALUES


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-01-18 : 10:33:04
quote:
Originally posted by Peso

ALTER TABLE <YourTableNameHere>
ADD <YourColumnNameHere> AS GETDATE() WITH VALUES


Peter Larsson
Helsingborg, Sweden



I think you meant DEFAULT, not AS:
ALTER TABLE <YourTableNameHere>
ADD <Your ColumnName> DATETIME NOT NULL DEFAULT (GETDATE()) WITH VALUES




CODO ERGO SUM
Go to Top of Page

allcaz
Starting Member

1 Post

Posted - 2007-02-01 : 11:39:54
What if you don't have rights to alter the table? Isn't there a hotkey you can use, or create, like Excel's CTRL+; ? Seems like this used to work in Enterprise Manager, but no longer works in SSMS.
Go to Top of Page
   

- Advertisement -