Getting account 'locked' status in SQL Server
I want to unlock one account in SQL Server. Before unlocking I have to check whether that account is locked or not.
I want to unlock only if the account is locked.
Is there any SQL query or stored procedure to get the "Loc开发者_StackOverflow社区ked" status of SQL user?
Posting Answer on Behalf of Alex K.
SELECT LOGINPROPERTY('loginname', 'IsLocked')
Do you mean a login name that has Login: Denied ? If so you can:
SELECT is_disabled from sys.server_principals WHERE name = @loginname
Listing all logins with unlocked statuses in all Databases (active all logins on all DBs)
SELECT name, is_disabled, LOGINPROPERTY(name, N'isLocked') as is_locked,
LOGINPROPERTY(name, N'LockoutTime') as LockoutTime into #tmp_is_disabled
FROM sys.sql_logins
WHERE LOGINPROPERTY(name, N'isLocked') = 0
select * from #tmp_is_disabled where is_disabled ='false'
~~regarding~~ ~~pektas~~
精彩评论