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 |
|
cshah1
Constraint Violating Yak Guru
347 Posts |
Posted - 2005-10-13 : 15:04:25
|
| which one should I use to record update made by userssuser_sname() or Current_User?Current_UserSystem_UserUser_NameSuser_Sname() |
|
|
peterlemonjello
Yak Posting Veteran
53 Posts |
Posted - 2005-10-13 : 16:24:32
|
| suser_sname() probably. |
 |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2005-10-13 : 17:03:49
|
| Agreed. On boxes where I am a sysadmin, CURRENT_USER returns "dbo", but SUSER_SNAME() returns my actual NT Login. SYSTEM_USER also returns the correct NT Login value.---------------------------EmeraldCityDomains.com |
 |
|
|
cshah1
Constraint Violating Yak Guru
347 Posts |
Posted - 2005-10-13 : 17:38:17
|
| That's right Current_User or User_Name returns dbo while system_user or suser_sname() returns their NT login huh weird..? |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2005-10-13 : 19:56:49
|
| It's not weird really: a user is a database object, a login is a server object. For the purposes you're describing I'd say you'd want SYSTEM_USER. |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-10-14 : 07:41:39
|
| Why are there so many of these things? I couldn't tell you what the subtle differences are ...SESSION_USER ??SUSER_NAME - dangerously like suser_Sname, yet deprecated and returns NULLSome have brackets so they look like functions SUSER_SNAME(), some don't SYSTEM_USER. For all I can remember there are probably some @@FOO_BAR ones too ...Any advance on:SESSION_USER - current session's usernameSYSTEM_USER - DOMAIN\user_login_name if using Windows Authentication, otherwise SQL Server login identification nameUSER_NAME() - database username - a.k.a USER and CURRENT_USERSUSER_SNAME() - login identification name - supersedes SUSER_NAME() Kristen |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2005-10-14 : 07:56:54
|
| The ones without parentheses are the ANSI SQL function names, they should work across multiple database platforms. SUSER_NAME() was quietly superseded by SUSER_SNAME() in SQL 7.0.All of these are documented in Books Online, and 60 seconds of playing with them in QA will show you which ones do what. |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-10-14 : 08:34:26
|
| "and 60 seconds of playing with them in QA will show you which ones do what"... provided you remember to log in to QA using either SQL Login or Windows Authentication as appropriate for the test you want to make!Kristen |
 |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-10-14 : 15:14:45
|
quote: Originally posted by Kristen "and 60 seconds of playing with them in QA will show you which ones do what"... provided you remember to log in to QA using either SQL Login or Windows Authentication as appropriate for the test you want to make!Kristen
Play with the SETUSER command as well.don't forget USER and CURRENT_USER There is quite a few.I commonly use SUSER_SNAME() |
 |
|
|
|
|
|