Hna
Hna

Reputation: 1006

Getting the OS User through SQL Authentication

I know I can grab the user's OS ID with the following but that only works if the user is logged in via windows authentication.

select nt_username from master..sysprocesses 

Is there anyway to do the same if the user is logged in with SQL Authentication?

Upvotes: 1

Views: 2721

Answers (1)

Nicholas Carey
Nicholas Carey

Reputation: 74315

If you are logged in via SQL authentication, there's no way to identify the user in SQL Server. All you got is the SQL Server user ID.

BTW, you should use the SQL Server built-in security functions to get this information, not the system tables:

  • CURRENT_USER
  • SESSION_USER
  • SYSTEM_USER
  • USER_ID()
  • USER_NAME()
  • SUSER_ID()
  • SUSER_NAME()

See Books Online for the details.

Upvotes: 2

Related Questions