从表里面导出数据XML:

  1. -- export
  2. declare @xml xml
  3. set @xml = (select * from (
  4. select TableName = 'Schema',
  5. xmlData = ( select * from [Schema] where id = 337 for xml auto, root('Schemas') )
  6. union
  7. select 'SchemaFile',
  8. ( select Id, SchemaId,
  9. Data = convert(varchar(max), Data),
  10. FileName, Fullpath, RelativePath
  11. from SchemaFile where SchemaId = 337 for xml auto, root('SchemaFiles') ) ) SchemaExport
  12. for xml auto, root('SchemaExports') )
  13.  
  14. select @xml

将导出XML数据插入到目的表中:

  1. -- now import
  2.  
  3. declare @idoc int
  4.  
  5. declare @tableName varchar(255)
  6. declare @xmlData xml
  7.  
  8. declare @mappingExport table (TableName varchar(255), xmlData xml)
  9.  
  10. exec sp_xml_preparedocument @idoc output, @xml
  11. insert into @mappingExport
  12. select *
  13. from openxml (@idoc, '/SchemaExports/SchemaExport')
  14. with (TableName varchar(255),
  15. xmlData nvarchar(max))
  16. exec sp_xml_removedocument @idoc output
  17.  
  18. declare exportCursor cursor
  19. for select TableName, xmlData
  20. from @mappingExport
  21.  
  22. open exportCursor
  23.  
  24. fetch from exportCursor into @tableName, @xmlData
  25.  
  26. while @@fetch_status <> -1
  27. begin
  28. exec sp_xml_preparedocument @idoc output, @xmlData
  29.  
  30. if (@tableName = 'Schema')
  31. begin
  32. print 'Copying Schema'
  33.  
  34. select *
  35. from openxml (@idoc, '/Schemas/Schema')
  36. with (Id int,
  37. TenantId int,
  38. VersionNo int,
  39. ResponseSchemaId int,
  40. SchemaName nvarchar(200),
  41. SOAPActino varchar(200),
  42. LastUpdatedUTC datetime,
  43. IsCanonical bit,
  44. DocumentType nvarchar(512) )
  45. end
  46. else if (@tableName = 'SchemaFile')
  47. begin
  48. print 'Copying SchemaFile'
  49. select *, datalength(data), convert(xml, data)
  50. from openxml (@idoc, '/SchemaFiles/SchemaFile')
  51. with (Id int,
  52. SchemaId int,
  53. Data varchar(max),
  54. FileName nvarchar(255),
  55. FullPath nvarchar(255),
  56. RelativePath nvarchar(255) )
  57. end
  58. exec sp_xml_removedocument @idoc
  59. fetch next from exportCursor into @tableName, @xmlData
  60. end
  61.  
  62. select datalength(data), convert(xml, data)
  63. from schemafile
  64. where schemaid = 337

Migration data on SQL的更多相关文章

  1. 如何用rake tasks 生成migration对应的sql

    how-to-use-rake-tasks-to-generate-migration-sql Rakefile文件里有load_tasks的方法 http://api.rubyonrails.org ...

  2. 7.4.1 Dumping Data in SQL Format with mysqldump

    7.4 Using mysqldump for Backups 使用mysqldump 用于备份: 7.4.1 Dumping Data in SQL Format with mysqldump 7. ...

  3. Rails Migration Data Model栏位修改及数据类型介绍

    测试版本Ruby:2.3.1   Rails:5.0.1 一.增加栏位       给devise默认的用户新增增加username字段 $ rails generate migration add_ ...

  4. [Android 开发教程(1)]-- Saving Data in SQL Databases

    Saving data to a database is ideal for repeating or structured data, such as contact information. Th ...

  5. 使用SQL Database Migration Wizard把SQL Server 2008迁移到Windows Azure SQL Database

    本篇体验使用SQL Database Migration Wizard(SQLAzureMW)将SQL Server 2008数据库迁移到 Azure SQL Database.当然,SQLAzure ...

  6. 6 ways to import data into SQL Server

    I’m going to go over some methods to import data from text files into SQL Server today. The particul ...

  7. Android学习笔记——保存数据到SQL数据库中(Saving Data in SQL Databases)

    知识点: 1.使用SQL Helper创建数据库 2.数据的增删查改(PRDU:Put.Read.Delete.Update) 背景知识: 上篇文章学习了保存文件,今天学习的是保存数据到SQL数据库中 ...

  8. Transfer data to SQL Server from SPC-Light with Excel macros

    公司的QA检测软件SPC-Light,需要从其中读取一些信息至SQL Server数据库,储存或是做其它分析. 先是在Excel的VBE的工具中,引入一个组件Microsoft ActiveX Dat ...

  9. Link static data in sql source control

    You can link data that doesn't change very often to SQL Source Control. This lets you commit data ch ...

随机推荐

  1. Unix/Linux环境C编程入门教程(7) OPENBSDCCPP开发环境搭建

    1. 年发起了OpenBSD 专案,希望创造一个注重安全的操作系统. 2.创建一个虚拟机. 3.选择默认的workstation10.0 4.我们选择稍后安装操作系统. 5.我们选择FreeBSD64 ...

  2. 面向对象程序设计-C++_课时28静态对象_课时29静态成员

    Static in C++ Two basic meanings Static Storage --allocated once at a fixed address Visibility of a ...

  3. javascript第二课javascript规范

    1.javascript严格区分大小写 2.声明变量一律使用var 推断类型 3.每条语句后面加分号 4.字符串使用单引号 5.html代码使用双引号,js用单引号

  4. 愤怒的DZY(二分)

    愤怒的DZY[问题描述]“愤怒的小鸟”如今已经是家喻户晓的游戏了,机智的WJC最近发明了一个类似的新游戏:“愤怒的DZY”.游戏是这样的:玩家有K个DZY,和N个位于不同的整数位置:X1,X2,…,X ...

  5. eclipse使用技巧---使用正则表达式查找替换

    1,Eclipse ctrl+f 打开查找框2,选中 Regular expressions (正则表达式) 去掉/* */(eclipse)        /\*(.|[\r\n])*?\*/去掉/ ...

  6. Oracle 关于V$OPEN_CURSOR

    参考链接:http://www.askmaclean.com/archives/about-dynamic-view-open_cursor.html#wrap 在之前的一次讨论中,有同行指出V$OP ...

  7. 穿透的 div ( pointer-events )

    pointer-events 是一個滿有趣的 CSS3 屬性,雖然主要是針對 SVG ,但其中幾個屬性應用在 div 上也是頗有意思.顧名思義,這是一個針對滑鼠事件的屬性,預設值為 auto,若值為 ...

  8. 线性插值(linear interpolation)

    线性插值通常用于:使用离散的样本来重建连续的信号.在计算机图形学中,这些样本可能是纹理.动画关键帧等. template <class T> T Lerp(T& a, T& ...

  9. C++_知识点_结构体/枚举/联合

    //C++中结构体的不同之处 #include <iostream> #include <string> using namespace std; int main(void) ...

  10. C++学习之this指针

    C++学习之this指针 一个对象的this指针并不是对象本身的一部分,不会影响sizeof(对象)的结果.this作用域是在类内部,当在类的非静态成员函数中访问类的非静态成员的时候,编译器会自动将对 ...