检查SQL Server 2005中是否存在登录的最佳方法是什么

时间:2020-12-10 09:15:03

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

我正在寻找检查SQL Server 2005中是否存在数据库登录的最佳方法。我目前正在使用

IF suser_sid('loginname') IS NOT NULL 

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

但suser_sid()在某些情况下返回一个值,其中登录不存在。

In SQL 2000 we use

在SQL 2000中我们使用

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

but that table does not exist in SQL 2005.

但SQL 2005中不存在该表。

There is a similar question about checking the existence of Users, which is helpful, but I am looking for the existence of Logins.

有关检查用户存在的类似问题,这是有帮助的,但我正在寻找登录的存在。

2 个解决方案

#1


For sql2005...

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

#2


syslogins is not recommended by Microsoft. It's better to use sys.server_principals.

Microsoft不建议使用syslogins。最好使用sys.server_principals。

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

#1


For sql2005...

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

#2


syslogins is not recommended by Microsoft. It's better to use sys.server_principals.

Microsoft不建议使用syslogins。最好使用sys.server_principals。

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