触发器用于根据情况防止插入数据 [英] Trigger For prevent inserting data According to a condition
问题描述
我需要一个触发器来防止某些数据插入表中根据条件,在像这样的代码中插入表中的任何行之前
i need a trigger that prevent some data from inserting in table According to a condition , before inserting any row in the table like this code
create Trigger trigger_name
on table_name
for insert
AS
Begin
if (true)
insert into table_name values ()
End
推荐答案
而不是触发器
(使用INSTEAD OF CLAUSE)
Instead of Trigger
(using INSTEAD OF CLAUSE)
这种类型的触发器在SQL Server开始执行$ b $之前触发b触发它的动作。这与AFTER触发器不同,后者在
动作触发后触发。我们可以在成功执行
但不包括对该表的实际插入/更新/删除的表上具有INSTEAD
的插入/更新/删除触发器。
This type of trigger fires before SQL Server starts the execution of the action that fired it. This is differ from the AFTER trigger, which fires after the action that caused it to fire. We can have an INSTEAD OF insert/update/delete trigger on a table that successfully executed but does not include the actual insert/update/delete to the table.
语法:
CREATE TRIGGER trigger_nameON {table|view}
[WITH ENCRYPTION|EXECUTE AS]
{FOR|AFTER|INSTEAD OF}
{[CREATE|ALTER|DROP|INSERT|UPDATE|DELETE ]}
[NOT FOR REPLICATION]
AS sql_statement [1...n ]
触发器应像这样的
CREATE TRIGGER trigger_name
ON table_name
instead OF INSERT
AS
BEGIN
IF (true)
INSERT INTO table_name VALUES ()
END
这篇关于触发器用于根据情况防止插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!