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
 General SQL Server Forums
 New to SQL Server Programming
 SQL Server TImestamp

Author  Topic 

gciszewski
Starting Member

1 Post

Posted - 2007-03-21 : 18:02:48
Hi,

I'm knew to SQL Server so forgive the rookie. I have used MySQL for about two years now, and I've done something there that I'd like to duplicate in SQL Server.

First off, I'm using SQL Server 2005 Express (free) edition. I have a table, and within the fields I have one titled "Last_Updated".

Now, I know that the function (when I place it in the default value) "getDate()" will insert the current date and time, but it doesn't update the record if the record is modified. What I'm looking for is if the user updates a record that the date/time automatically updates. I experimented with the Timestamp, but all it gave me was "binary data" in the field. Ideally I'm looking for something like this:

...using the YYYYMMDDHHMMSS format...
Last_Updated = 20070321140001

Is there a syntax for a default value that I'm missing? I've looked at several discussion groups, all giving varying advice, and none of which seemed to work. I much appreciate any guidance anyone can give me. Thanks!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-03-21 : 18:17:08
You can set the default value for the column to be GETDATE(). You can add the default constraint using ALTER TABLE. Check SQL Server Books Online for ALTER TABLE syntax.

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-03-21 : 20:18:01
I think you would need to use a trigger in order to accomplish updating the Last_Updated field. Of course if all data access is through stored procedures, then you can take care of it there. There may be a new way in 2005 to do this also, but I'm not aware of it.

-Ryan
Go to Top of Page
   

- Advertisement -