查找运行DROP COLUMN语句的用户

时间:2015-11-06 05:18:22

标签: sql-server

请查看以下内容

USE [ExperimentalDB]
GO

--Create table tblTestEmployee
CREATE TABLE [dbo].[tblTestEmployee]
(
    [EmployeeID] [int] IDENTITY(1,1) NOT NULL,
    [EmpName] [varchar](100) NOT NULL,
    [Address] [varchar](100) NOT NULL
)

--Populate some records to the tblTestEmployee
INSERT INTO [dbo].[tblTestEmployee] 
VALUES('Emp1','Address1'),('Emp2','Address2'),('Emp3','Address3'),('Emp4','Address4')

--Drop the column Address
ALTER TABLE [dbo].[tblTestEmployee] DROP COLUMN [Address] --ONLY this

--Drop the table
DROP TABLE [dbo].[tblTestEmployee] -- NOT  THIS

--Find who has done that
SELECT [Transaction Id], [Begin Time], SUSER_SNAME ([Transaction SID]) AS [User],[Transaction Name],Operation,[Transaction SID]
FROM fn_dblog (NULL, NULL)

我的目标是找出谁放弃了专栏[地址]

但是通过查看 fn_dblog 的输出,我无法弄清楚。 任何人都可以帮助我。

感谢。

1 个答案:

答案 0 :(得分:1)

使用以下内容显示与DROP命令

相关的所有日志
GO
SELECT 
Operation,
[Transaction Id],
[Transaction SID],
[Transaction Name],
[Begin Time],
[SPID],
Description
FROM fn_dblog (NULL, NULL)
WHERE [Transaction Name] = 'DROPOBJ'
GO

从上面的结果集中获取事务SID 并将其传递给系统函数SUSER_SNAME()以获取确切的用户名:

SELECT SUSER_SNAME(SID)