我有两个表tablea和tableb,根据条件将表b中部分数据插入表a,我的XXX代表这个自增序列,
insert into tablea (id, time,name)
select XXX ,getdate() ,name from tableb T2
where not exists(select 1 from tablea
where
tablea.name = T2.name
);
这条语句用触发器实现当插入一行时候XXX自增1?
insert into tablea (id, time,name)
select XXX ,getdate() ,name from tableb T2
where not exists(select 1 from tablea
where
tablea.name = T2.name
);
这条语句用触发器实现当插入一行时候XXX自增1?
select XXX+1 ,getdate() ,name from tableb T2
where not exists(select 1 from tablea
where
tablea.name = T2.name
);
我使用一个触发器
create table GlobalSeq
(global_id bigint)
insert into GlobalSeq values(1) CREATE trigger ko on tablea
after insert
AS
BEGIN
declare @cur int select @cur=max(global_id) from dbo.GlobalSeq
update temp set tableid=@cur where XXXXX
set @cur = @cur+1;
update GlobalSeq set global_id = @cur
end
这里的Where条件应该如何写?
insert into tablea (id, time,name)
select id=ROW_NUMBER () OVER(order by XXX) ,getdate() ,name from tableb T2
where not exists(select 1 from tablea
where
tablea.name = T2.name
);
这个id要实现自增,我的XXX只是一个例子而已