14 June,2018 by Tom Collins
Question: I'm logged onto a SQL Server 2016 instance using Windows Authentication and executing SELECT CURRENT_USER. Although I have sysadmin rights - the result always returns dbo.
What I need is to return my domain account name. Can you help?
Answer: There is a difference between CURRENT_USER and SYSTEM_USER.
SELECT CURRENT_USER - Returns the name of the current user. This function is equivalent to SELECT USER_NAME().
If the current user is a sysadmin privilege , the recordset returns “dbo”, rather than the logon name. Which because your current logon has sysadmin privileges explains the dbo result
SELECT SYSTEM_USER (also synonym for SUSER_SNAME(). - Returns the login name associated with a security identification number. SELECT SYSTEM_USER will return your domain name
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |