How to change current_user to display dbo

04 November,2019 by Jack Vamvas

Question: Currently when I execute the sql code - SELECT CURRENT_USER , the return is my login name . I'd like to change the result to display dbo , as there are a number of application code which rely on the login name to be dbo. 

How can I change the recordset to display dbo?

 

Answer: The easiest way to change the SELECT CURRENT_USER - result is to change the privilege to sysadmin. There are more details on  select current_user shows dbo   . The quick summary  is if the current user is a sysadmin privilege , the recordset returns “dbo”, rather than the logon name. 

You mention in the question that you're relying on the CURRENT_USER to use as a value for application code. This is not a great idea - as it introduces  risk into your application - which you can avoid. For example , if the login privileges change than the application code will break or cause an unexpected result which may go undetected and make troubleshooting difficult. Introducing this  SQL Antipattern   will only make the environment you manage more complex.

Develop a method within the application code to gracefully apply the naming schemas - through various functions to check the input parameters 


Author: Jack Vamvas (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

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.

Working...

Post a comment on How to change current_user to display dbo


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer