Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query for users associated with a login

Author  Topic 

bgard6977
Starting Member

1 Post

Posted - 2007-04-27 : 16:46:18
Is there anyway to query for what users are associated with a given login? I am writing an web app that allows people to change the password for thier login, except that I don't want to let them change that password unless they are the only user associated with it.

Currently I am generating a queries in a for/next loop, one for each DB on the server, then unioning them together. Except the server has several hundred DB's and the operation is timing out.

It looks kind of like this:

select 'Database1' as DbName
from master.db.syslogins l
inner join Database1.dbo.sysusers u
on l.sid=u.sid
where l.loginname='username'

union
select 'Database2' as DbName
from master.db.syslogins l
inner join Database2.dbo.sysusers u
on l.sid=u.sid
where l.loginname='username'

Any help would be, well, helpful :-)
   

- Advertisement -