博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
存档数据迁移
阅读量:4213 次
发布时间:2019-05-26

本文共 1206 字,大约阅读时间需要 4 分钟。

;
with tb1 as (
select a.name as sch,b.name as tbl,c.name as col 
from sys.schemas a ,sys.all_objects b ,sys.all_columns c 
where a.schema_id=b.schema_id and b.type='u' 
and a.name like 'hist%'
and b.object_id=c.object_id),
tb2 as (select distinct sch,tbl from tb1)
select sch,tbl,
'
begin tran 
begin try
set identity_insert '+quotename('hist_'+db_name())+'.'+quotename(sch)+'.'+quotename(tbl)+' on;
insert into '+quotename('hist_'+db_name())+'.'+quotename(sch)+'.'+quotename(tbl)+'
(
'+stuff((select ','+quotename(col) from tb1 b where b.sch=a.sch
and b.tbl=a.tbl for xml path('')),1,1,'') +'
)
select '+stuff((select ','+quotename(col) from tb1 b where b.sch=a.sch
and b.tbl=a.tbl for xml path('')),1,1,'') +'
from '+quotename(db_name())+'.'+quotename(sch)+'.'+quotename(tbl)+' ;
set identity_insert '+quotename('hist_'+db_name())+'.'+quotename(sch)+'.'+quotename(tbl)+' off;
drop table '+quotename(db_name())+'.'+quotename(sch)+'.'+quotename(tbl)+';
commit tran 
print '''+quotename(db_name())+'.'+quotename(sch)+'.'+quotename(tbl)+'迁移成功!''
end try
begin catch 
print '''+quotename(db_name())+'.'+quotename(sch)+'.'+quotename(tbl)+'迁移失败!''+error_message()
rollback tran
print ''
已回滚''
end catch
'
 from tb2 a;
 

转载地址:http://nofmi.baihongyu.com/

你可能感兴趣的文章
mongodb group 有条件的过滤组合个数。
查看>>
关于mongodb的 数组分组 array group
查看>>
MongoDB新的数据统计框架介绍
查看>>
mongodb 增加全文检索索引
查看>>
mysql数据库主从同步的问题解决方法
查看>>
LoadRunner如何在脚本运行时修改log设置选项?
查看>>
QC数据库表结构
查看>>
自动化测试工具的3个关键部分
查看>>
测试工具厂商的编程语言什么时候“退休”?
查看>>
资源监控工具 - Hyperic HQ
查看>>
LoadRunner中Concurrent与Simultaneous的区别
查看>>
SiteScope - Agentless监控
查看>>
使用QTP的.NET插件扩展技术测试ComponentOne的ToolBar控件
查看>>
用上帝之眼进行自动化测试
查看>>
为LoadRunner写一个lr_save_float函数
查看>>
PrefTest工作室全新力作-《性能测试与调优实战》课程视频即将上线
查看>>
质量度量分析与测试技术 培训大纲
查看>>
欢迎加入【亿能测试快讯】邮件列表!
查看>>
为什么我们的自动化测试“要”这么难
查看>>
LoadRunner性能脚本开发实战训练
查看>>