SQL server 2008 r2上次数据库用户的日期和时间



如何查找最后一个数据库用户日期和时间sql server 2008 r2?

你可以试试这个:

SELECT accdate, name FROM master.dbo.syslogins

或使用

select max (login_time), login_name 
from sys.dm_exec_sessions
group by login_name;

您可以设置一个所谓的登录触发器。

示例:

USE master;
GO
CREATE LOGIN login_test WITH PASSWORD = '3KHJ6dhx(0xVYsdf' MUST_CHANGE,
    CHECK_EXPIRATION = ON;
GO
GRANT VIEW SERVER STATE TO login_test;
GO
CREATE TRIGGER connection_limit_trigger
ON ALL SERVER WITH EXECUTE AS 'login_test'
FOR LOGON
AS
BEGIN
IF ORIGINAL_LOGIN()= 'login_test' AND
    (SELECT COUNT(*) FROM sys.dm_exec_sessions
            WHERE is_user_process = 1 AND
                original_login_name = 'login_test') > 3
    ROLLBACK;
END;

示例取自https://msdn.microsoft.com/en-us/library/bb326598(v=sql.105).aspx

相关内容

  • 没有找到相关文章

最新更新