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
 record author automatically

Author  Topic 

allan8964
Posting Yak Master

249 Posts

Posted - 2012-03-15 : 09:35:43
Hi there,

I wonder if it's possible to keep the record of an author in a col. For example, in table1 I have cols:

tableID | Event | Date | Author |...

I know I can set Date as Getdate() by constraint or a trigger, further I need Author col populated automatically by the userAcct who insert, edit or delete the row. Is this possible? Thanks in advance.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-03-15 : 09:54:26
Set USER_NAME() and GETDATE() as default values.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

allan8964
Posting Yak Master

249 Posts

Posted - 2012-03-15 : 10:18:14
Thanks SwePeso. But I tried select user_name(), it returns dbo, not a user acct. I need exact user name or acct name. Thanks
Go to Top of Page

allan8964
Posting Yak Master

249 Posts

Posted - 2012-03-15 : 10:27:01
Did some research and found that user_name(id) returns impersonated info without id added, fro automatically added user we can use defaut with current_user set on the column of author. Thanks.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-03-15 : 11:36:48
select system_user


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

allan8964
Posting Yak Master

249 Posts

Posted - 2012-03-15 : 12:54:10
oh yeah, you're so good. It returns the user account with domain name. that's exactly what I'm looking for! THANKS!!!
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-15 : 12:57:38
Author of???

Do you use a single connection pooling id to log in? And do you authenticate your users somewhere else?

Like we do, you need to require the calling application to supply the logged in userid to the called sproc..we do it for everything we write



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -