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.
| Author |
Topic |
|
allan8964
Posting Yak Master
249 Posts |
Posted - 2012-02-16 : 14:10:37
|
| Hi there,Is it possible to automatically fill a datetime typed field? Like this table:ID | Name | FillDate | ...11 | John | 12/02/2012 |...I want the field FillDate automatically filled with current date time when the record saved. Thanks in advance. |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2012-02-16 : 14:20:44
|
| Create Table YourTable ( ID int, Name Varchar(32), FillDate datetime NOT NULL DEFAULT getdate()) |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-16 : 15:37:54
|
| Please keep in mind that creating a default like in previous suggestions will auto populate values only for new inserts. If you want current date value to be captured even for update operations as well, you might need a separate trigger for that.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
allan8964
Posting Yak Master
249 Posts |
Posted - 2012-02-17 : 17:16:27
|
| Thanks gents for the guide. Actually I noticed that the constraints not working with update, Yes I need to create a trigger for that. |
 |
|
|
|
|
|
|
|