• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 494
  • Last Modified:

How do I get the DB Username from LoginName?

Using T-SQL:

I know the LOGIN NAME of a user. How can I find the USER NAME that is associated with the login name for a particular database?

Thanks
Bob

0
rcl58
Asked:
rcl58
  • 3
  • 3
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
check out the master.sys.syslogins sid column vs the databases.sys.sysusers sid column ...
0
 
rcl58Author Commented:
angelIII,

Thanks for your help. I am just trying to drop a user's login and database user. Since I know the Login Name I can drop the login easily but I don't see a T-SQL command to drop a user from a database using the Login Name or SID. How would I do this? Do I have to directly access tables in the master database?

Thanks again,
Bob
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
rcl58Author Commented:
Sorry for being slow but I still don't follow.

e.g. Say login name is [mydomain\bsmith] and my user name is [bob]

If I only know the login name how can I find the user name? DROP USER requires the user name.

Thanks
Bob
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
select l.name login_name, u.name user_name
from master.sys.syslogins l
join reportserver.sys.sysusers u
  on u.sid = l.sid
where l.name = 'mydomain\bsmith'
0
 
rcl58Author Commented:
Thanks again
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now