sql server如何建判断某值满足条件就不插入该行的触发器

比如向test表插入数据,如果插入的某行数据的a列值为1就不插入该行数据
该怎么写

Create Trigger trtest
On test --在test表中创建触发器
for Update --为什么事件触发
As --事件触发后所要做的事情
DECLARE @a int
SET @a = select a from updated
if (@a=1)
begin
ROLLBACK
end追问

应该不是update的吧,而且提示:在关键字 'select' 附近有语法错误。

我要的效果是这样:
create table test(a int,b char(10));
insert into test values(0,'fu'); --a的值为0的就不让插入
insert into test values(2,'fu'); --a值为其他的可以插入

追答

这个是update触发器
Create Trigger trtest
On test --在test表中创建触发器
for Update --为什么事件触发
As --事件触发后所要做的事情
DECLARE @a int
SET @a = (select a from updated)
if (@a=1)
begin
ROLLBACK
end

这个是insert触发器
Create Trigger trtest
On test --在test表中创建触发器
for insert --为什么事件触发
As --事件触发后所要做的事情
DECLARE @a int
SET @a = (select a from updated)
if (@a=1)
begin
ROLLBACK
end

温馨提示:答案为网友推荐,仅供参考
相似回答