27,579
社区成员
发帖
与我相关
我的任务
分享
(select matchA='1NHXjRVE9L41',matchB='3NHXjRVE9L41',matchC='bc1NHXjRVE9L41' union all
select matchA='1JB4SXThJJFg',matchB='3JB4SXThJJFg',matchC='bc1JB4SXThJJFg' union all
select matchA='1KveoNMcyvJc',matchB='3KveoNMcyvJc',matchC='bc1KveoNMcyvJc' union all
select matchA='19B1tyo6372X',matchB='39B1tyo6372X',matchC='bc19B1tyo6372X')
数据插入到T表的同时能否同时按以下条件更新ABC这3张表:
create proc [存储过程名]
(@matchA varchar(1000),
@matchB varchar(1000),
@matchC varchar(1000))
as
begin
begin try
begin tran
insert into T表(matchA,matchB,matchC) select @matchA,@matchB,@matchC
update A表 set 识别=1 where 地址=@matchA and 识别=0
update B表 set 识别=1 where 地址=@matchB and 识别=0
update C表 set 识别=1 where 地址=@matchC and 识别=0
commit tran
end try
begin catch
rollback tran
end catch
end
create index ix_A_matchA on A(matchA);
create index ix_B_matchB on A(matchB);
create index ix_C_matchC on C(matchC);
create index ix_T_matchA on T(matchA);
create index ix_T_matchB on T(matchB);
create index ix_T_matchC on T(matchC);
2. 已更新过的数据是否下次还要更新?如果不用,那可以只取需要更新的。
类似:
update AA
SET AA.flag=1, needUpdate=0
from A as AA inner join T on AA.matchA=T.matchA
where AA.needUpdate=1