如果我理解你的需要,那就应该工作。 我在2008年5月5日对它进行了测试,但我看不出为什么它不会在2005年服务器上工作。
采用标识触发器在审计表中插入一行。
• 在你的审计桌上设立AFTER INSERT触发点,删除与MIN(ID)的行文。
Here s some code to play with:
∗ 编制审计表 *
CREATE TABLE ServerLogonHistory
(SystemUser VARCHAR(512),
ID BIGINT,
DBUser VARCHAR(512),
SPID INT,
LogonTime DATETIME)
GO
/* Create Logon Trigger */
CREATE TRIGGER Tr_ServerLogon
ON ALL SERVER FOR LOGON
AS
BEGIN
INSERT INTO TestDB.dbo.ServerLogonHistory
SELECT SYSTEM_USER, MAX(ID)+1 , USER,@@SPID,GETDATE()
FROM TestDB.dbo.ServerLogonHistory;
END
GO
∗ 建立清理触发点 *
CREATE TRIGGER AfterLogin
ON TestDB.dbo.ServerLogonHistory
AFTER INSERT
AS
DELETE
FROM TestDB.dbo.ServerLogonHistory
WHERE ID =
(SELECT MIN(ID) FROM TestDB.dbo.ServerLogonHistory);
GO;
A word of warning. If you create an invalid logon trigger, you ll not be able to logon to the database. But don t panic! It s all part of learning. You ll be able to use sqlcmd to drop the bad trigger.
我确实试图删除标识触发器中的min光灯,但我无法做到这一点。