Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I get the DB Username from LoginName?

Posted on 2007-11-23
6
Medium Priority
?
491 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 143

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 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20340548
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 400 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

926 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