Shawn Weisfeld

I find when I talk to myself nobody listens. - Shawn Weisfeld
posts - 356, comments - 173, trackbacks - 34

My Links

News

The views expressed in this blog are mine and mine alone, not that of my employer, Microsoft, or anyone else’s. No warrantee is given for the quality of any material on this site.

Archives

Post Categories

SQL Server: Who am I?

Got a question today. How do I tell what user my sql server query is running as? Well you just ask.

Using the USER_NAME() function, without passing it an id, finds the name of the current user.

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

Using the SUSER_NAME() function, gets me the login identification name of the user.

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

 

Here is an example of each, using both a regular sql server login (left) and windows authentication (right)

image

 

Now that I know who I am, why not be someone else. . . In this example I change the context that I am running under with the “EXECUTE AS LOGIN” statement, then I revert back using . . . wait for it. . . the “REVERT” statement.

EXECUTE AS: http://msdn.microsoft.com/en-us/library/ms181362.aspx

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

image 

 

and they say getting to know ones self is hard. . .

Print | posted on Thursday, June 11, 2009 3:48 AM | Filed Under [ SQL ]

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 4 and 6 and type the answer here:

Powered by: