Solved

How do I get the DB Username from LoginName?

Posted on 2007-11-23
6
486 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

623 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