34,594
社区成员
发帖
与我相关
我的任务
分享
create table a
(
id int identity,
A1 int
)
insert a (A1)
values
(2),
(3),
(10),
(20)
select * from a
create procedure sp_AA
@id int
as
begin
declare @r int;
set @r=(select COUNT(*) from a where ID=@id and A1>10);
if @r>=1
begin
update a set A1=A1+1 where id=@id;
print 1
end
else
begin
print 0
end
end
写个存储过程就可以了update A set A1 = A1 + 1 where id = '1' AND A1<=9
直接用条件限制,貌似可以直接这样
drop table A
go
create table A(id int identity , A1 int)
go
select * from A
go
create trigger A_ins
on A after insert , update
as
begin
update A set A.A1 = 10 where A.id in (select id from inserted where A1 >10)
end
go
insert into A(A1) values(1)
insert into A(A1) values(2)
insert into A(A1) values(100)
insert into A(A1) values(101)
go
select * from A
go
id A1
----------- -----------
(0 行受影响)
id A1
----------- -----------
1 1
2 2
3 10
4 10
(4 行受影响)