SQL Server 2005 Get username as username

How can I specify a username for a specific database and get a request for that user in the request?

Thanks.

+4
source share
3 answers

Using Security Directory Views , you can get basic information about the database and server, for example:

USE [database_name] SELECT sp.name AS login_name FROM sys.server_principals sp JOIN sys.database_principals dp ON (sp.sid = dp.sid) WHERE dp.name = 'user_name' 

I can’t find a view that will give you all users, regardless of the database, so this needs to be run in the context of the login database.

+8
source
 select * FROM sys.server_principals AS log WHERE (log.type in ('U', 'G', 'S', 'C', 'K') AND log.principal_id not between 101 and 255 AND log.name <> N'##MS_AgentSigningCertificate##') 
+2
source

Or you can use the sp_helpuser system stored procedure.

 exec sp_helpuser 'Username' 
+2
source

All Articles