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;
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744219871a4563730.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