我可以使用指定数据库的服务器触发器阻止插入到所有表中吗
答案 0 :(得分:1)
如果您希望通过编写服务器触发器来防止将记录插入任何表中,那么答案就是不可能。
服务器触发器只处理DDL(CREATE,ALTER,DROP ...)而不处理DML(INSERT,UPDATE,DELETE):
https://msdn.microsoft.com/en-us/library/ms189799.aspx
服务器触发器:
-- Trigger on a CREATE, ALTER, DROP, GRANT, DENY, REVOKE,
-- or UPDATE STATISTICS statement (DDL Trigger)
CREATE TRIGGER trigger_name
ON { ALL SERVER | DATABASE }
[ WITH <ddl_trigger_option> [ ,...n ] ]
{ FOR | AFTER } { event_type | event_group } [ ,...n ]
AS { sql_statement [ ; ] [ ,...n ] | EXTERNAL NAME < method specifier > [ ; ] }
<ddl_trigger_option> ::=
[ ENCRYPTION ]
[ EXECUTE AS Clause ]
-- Trigger on a LOGON event (Logon Trigger)
CREATE TRIGGER trigger_name
ON ALL SERVER
[ WITH <logon_trigger_option> [ ,...n ] ]
{ FOR| AFTER } LOGON
AS { sql_statement [ ; ] [ ,...n ] | EXTERNAL NAME < method specifier > [ ; ] }
<logon_trigger_option> ::=
[ ENCRYPTION ]
[ EXECUTE AS Clause ]