SqlServer2005 怎样建触发器 防止数据表被删除?????
--创建删除触发器createtriggerdeletetriggeron错误日志fordeleteasif(droptable错误日志)beginprint'你不能删除...
--创建删除触发器
create trigger deletetrigger on 错误日志 for delete
as
if(drop table 错误日志)
begin
print '你不能删除错误日志'
rollback transaction ;
end
这是代码 求大师解答啊啊啊啊!!!! 展开
create trigger deletetrigger on 错误日志 for delete
as
if(drop table 错误日志)
begin
print '你不能删除错误日志'
rollback transaction ;
end
这是代码 求大师解答啊啊啊啊!!!! 展开
2013-11-04
展开全部
我这里有一个 创建表的触发器, 你参考着修改修改成 删除表的吧
1> CREATE TRIGGER CretaeTableTrigger
2> ON DATABASE
3> FOR CREATE_TABLE
4> AS
5> BEGIN
6> DECLARE @EventData AS xml;
7>
8> DECLARE @EventType AS varchar(100);
9> DECLARE @PostTime AS varchar(100);
10> DECLARE @ServerName AS varchar(100);
11> DECLARE @LoginName AS varchar(100);
12> DECLARE @DatabaseName AS varchar(100);
13> DECLARE @CommandText AS varchar(100);
14>
15> SET @EventData = EVENTDATA();
16>
17> SELECT
18> @EventType = t.c.value('(EventType)[1]', 'varchar(100)' ),
19> @PostTime = t.c.value('(PostTime)[1]', 'varchar(100)' ),
20> @ServerName = t.c.value('(ServerName)[1]', 'varchar(100)' ),
21> @LoginName = t.c.value('(LoginName)[1]', 'varchar(100)' ),
22> @DatabaseName = t.c.value('(DatabaseName)[1]', 'varchar(100)' ),
23> @CommandText = t.c.value('(TSQLCommand/CommandText)[1]', 'varchar(100
)' )
24> FROM
25> @EventData.nodes('/EVENT_INSTANCE') t(c);
26>
27> PRINT( 'CREATE_TABLE' );
28> PRINT( @EventType );
29> PRINT( @PostTime );
30> PRINT( @ServerName );
31> PRINT( @LoginName );
32> PRINT( @DatabaseName );
33> PRINT( @CommandText );
34> END
35> go
1> create table yyy (a INT);
2> go
CREATE_TABLE
CREATE_TABLE
2010-10-01T21:32:24.843
HOME-BED592453C\SQLEXPRESS
HOME-BED592453C\wzq
Stock
create table yyy (a INT);
更多追问追答
追问
大神 我是菜鸟级别的 看不太懂 大神能帮我解决么??????
追答
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER DropTableTrigger
ON DATABASE
FOR DROP_TABLE
AS
BEGIN
DECLARE @EventData AS xml;
DECLARE @EventType AS varchar(100);
DECLARE @CommandText AS varchar(100);
SET @EventData = EVENTDATA();
@EventType = t.c.value('(EventType)[1]', 'varchar(100)' ),
@CommandText = t.c.value('(TSQLCommand/CommandText)[1]', 'varchar(100)' )
FROM
@EventData.nodes('/EVENT_INSTANCE') t(c);
PRINT( @EventType );
PRINT( @CommandText );
IF (CHARINDEX(' Test12345', @CommandText) > 0)
BEGIN
PRINT 'Test12345 表不能删除的哦 ^_^';
ROLLBACK;
END
END
go
CREATE TABLE Test12345(id int)
GO
DROP TABLE Test12345
GO
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询