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 |
|
dealwi8me
Starting Member
13 Posts |
Posted - 2009-04-10 : 02:18:23
|
Hello,i'm just getting started with triggers and i would like some help.When a new record is inserted into table tblProducts, i want to set automatically the fields UserInsert= Windows Logon (environmemt) and DateInserted= current date and time.Any suggestions?Thank you in advance  |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-04-10 : 03:50:39
|
You don't need a trigger for that!Just use DEFAULT values for the columns. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
dealwi8me
Starting Member
13 Posts |
Posted - 2009-04-10 : 04:11:10
|
| Thank you for your answer.I tried using Date() but i get error.What are the fuctions i should use? |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-04-10 : 04:12:13
|
| getdate() |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-04-10 : 04:12:55
|
| or CURRENT_TIMESTAMP |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-04-10 : 06:21:56
|
| please keep in mind that creation of defaults will populate the values automatically only during inserts. if you want this to happen also for updates, then you need a trigger. |
 |
|
|
dealwi8me
Starting Member
13 Posts |
Posted - 2009-04-10 : 14:40:53
|
| @visakh16 i only need this during insertions, thank you though.What about user name (Windows log on) how can i get it? |
 |
|
|
dealwi8me
Starting Member
13 Posts |
Posted - 2009-04-10 : 14:49:31
|
| I found the solution! ...with your help of course!In case someone else has the same questions i used getdate() for getting current date and time and suser_sname() for getting the user who performed the insertion.Thank you all for your help.[:) |
 |
|
|
|
|
|