What is the best way to check if there is a login in SQL Server 2005

I am looking for the best way to check that the database login exists in SQL Server 2005. I am currently using

IF suser_sid('loginname') IS NOT NULL 

      

but suser_sid () returns a value in some cases when the login does not exist.

In SQL 2000 we use

SELECT * FROM [Master].[dbo].[sysxlogins] WHERE [name] ='loginname'

      

but this table doesn't exist in SQL 2005.

There is a similar question about checking the existence of users , which is helpful, but I'm looking for the existence of logins.

+1


source to share


2 answers


For sql2005 ...



select * from master.sys.syslogins WHERE [name] ='loginname'

      

+2


source


syslogins

not recommended by Microsoft. Better to use sys.server_principals

.



select * from sys.server_principals where name = 'login_name'

      

0


source







All Articles