Solved

How do I get the DB Username from LoginName?

Posted on 2007-11-23
6
480 Views
Last Modified: 2013-11-06
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
Comment
Question by:rcl58
  • 3
  • 3
6 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20340440
check out the master.sys.syslogins sid column vs the databases.sys.sysusers sid column ...
0
 

Author Comment

by:rcl58
ID: 20340538
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
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20340548
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:rcl58
ID: 20340604
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
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
ID: 20340634
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
 

Author Comment

by:rcl58
ID: 20340699
Thanks again
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now