Link to home
Start Free TrialLog in
Avatar of DevSupport
DevSupport

asked on

listing SQL login names of valid databases

I am trying to list the logins in MS SQL database from sys.server_principals table.

But I am trying to get only those logins which have valid databases, I can see that the sys.server_principals table have logins which are associated to old default databases which does not exist.

I am trying to make something like:

SELECT * FROM sys.server_principals where default_database_name = (select name from sys.databases) AND type_desc = 'SQL_LOGIN'

I would really appreciate if you could help me with a query.

Thanks
DevSupport
Avatar of DevSupport
DevSupport

ASKER

Does this sound correct?

select * from sys.server_principals A where A.default_database_name IN (select name from sys.databases) AND A.type_desc = 'SQL_LOGIN'
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial