读书人

怎样用sql语句把一个表内容导入另一个

发布时间: 2012-01-01 23:10:55 作者: rapoo

怎样用sql语句把一个表内容导入另一个一样结构的表中,同一数据库
我想用作业 每晚在2点钟 运行一个存储过程 ,把一个表的部分内容(如前10000行)全部导入到另一个表中,他们表结构一样,然后把原表已导入过去的数据删除。

原表中有id自增列。




[解决办法]
--try

begin tran

insert B(colName)
select top 10000 colName
from A
order by id

delete A
where id in(select top 10000 colName from A order by id)

if @@error=0
commit tran
else
rollback tran

[解决办法]
begin tran
drop table b
if @@error <> 0 goto err_a
select top 10000 * insert into b from a
if @@error <> 0 goto err_a
commit tran
return
err_a:
rollback tran

读书人网 >SQL Server

热点推荐