2015-11-06 45 views
0

请看下面寻找谁跑了DROP COLUMN语句

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,我无法弄清楚。 任何人都可以帮助我。

谢谢。

+0

我创建了[dbhistory.com](http://dbhistory.com)来回答这样的问题。 –

回答

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)

+0

@!Aishvarya Karthik,但我只想知道谁已删除列 –

+0

第二个查询会给你结果 – MusicLovingIndianGirl

+0

对,我得到的结果,但只想知道哪些用户已删除列,没有任何其他的东西如表等 –