admin管理员组文章数量:1401149
I have been doing some research on the SA user account in SQL.
I placed the SELECT * FROM syslogins
statement and in the hasaccess column the SA user appears with 1. However, when checking the Microsoft SQL Server screen, it appears to me with the X, which I interpret as not having access.
My question is, why does hasaccess=1 appear if SA user is disabled?
I have been doing some research on the SA user account in SQL.
I placed the SELECT * FROM syslogins
statement and in the hasaccess column the SA user appears with 1. However, when checking the Microsoft SQL Server screen, it appears to me with the X, which I interpret as not having access.
My question is, why does hasaccess=1 appear if SA user is disabled?
Share Improve this question asked Mar 25 at 2:28 G07G07 12 bronze badges 3 |1 Answer
Reset to default 2To expand what has been stated at in the comments, let's first look at sys.syslogins (Transact-SQL), which very clearly states:
Important
This SQL Server 2000 system table is included as a view for backward compatibility. We recommend that you use the current SQL Server system views instead. To find the equivalent system view or views, see Mapping System Tables to System Views (Transact-SQL). This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.
So, quite clearly, you should not be using sys.syslogins
. The correct system view to use is either sys.server_principals or sys.sql_logins, per the linked documentation in the quote block above.
To find out if a LOGIN
is disabled, you would check the value of is_disabled
using either of those views. 0
denotes the login is enabled, and 1
disabled:
DECLARE @LoginName sysname = N'sa';
SELECT is_disabled
FROM sys.server_principals
WHERE name = @LoginName;
SELECT is_disabled
FROM sys.sql_logins
WHERE name = @LoginName;
本文标签: sql serverHow can I know if the SA user is disabledStack Overflow
版权声明:本文标题:sql server - How can I know if the SA user is disabled? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744219870a2595814.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
syslogins
is deprecated. You should be usingsys.server_principals
orsys.sql_logins
and then the answer is obvious – Martin Smith Commented Mar 25 at 2:49syslogins
.syslogins
is fromSQL Server 2000
and TheEnable/Disable
feature of a login is not available inSQL Server 2000
. Sohasaccess
does not represent the stateEnable/Disable
of a login in newer version ofSQL Server
– Squirrel Commented Mar 25 at 2:50