34,594
社区成员
发帖
与我相关
我的任务
分享
insert into b
select * from a
DELETE FROM b
WHERE ID IN (SELECT TOP 1 ID FROM b)
INSERT INTO b
SELECT * FROM a WHERE id>(SELECT TOP 1 id FROM a)
--> 数据库版本:
--> Microsoft SQL Server 2008 (RTM) - 10.0.1600.22
--> 测试数据:tb1
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'tb1')
AND type in (N'U'))
DROP TABLE tb1
GO
---->建表
create table tb1([id] int,[data] int)
insert tb1
select 2,23213 union all
select 3,12313 union all
select 4,51531 union all
select 5,12341
GO
--> 查询结果
SELECT * FROM tb1
--对比
;with t as(
select * ,row_number()over(order by id) as px
from tb1)
select id,data from t
where px>1
--> 删除表格
--DROP TABLE tb1
with t as(
select * ,row_number()over(order by id) as px
from tb1)
insert into tb2(id,data)
select id,data from t
where px>1
insert into tb2(id,data)
select id,data from tb1
where id>1---这个条件你根据实际情况写
insert A (select * from B Where id=id+1)