Migration data on SQL

从表里面导出数据XML:

-- export
declare @xml xml
set @xml = (select * from (
select TableName = ‘Schema‘,
       xmlData = ( select * from [Schema] where id = 337 for xml auto, root(‘Schemas‘) )
union
select ‘SchemaFile‘,
       ( select Id, SchemaId,
                Data = convert(varchar(max), Data),
                FileName, Fullpath, RelativePath
         from SchemaFile where SchemaId = 337 for xml auto, root(‘SchemaFiles‘) ) ) SchemaExport
for xml auto, root(‘SchemaExports‘)      )

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
时间: 2024-10-10 02:16:55

Migration data on SQL的相关文章

Guide to Database Migration from Microsoft SQL Server using MySQL Workbench

http://mysqlworkbench.org/2012/07/migrating-from-ms-sql-server-to-mysql-using-workbench-migration-wizard/ http://www.mysql.com/products/workbench/migrate/ Guide to Database Migration from Microsoft SQL Server using MySQL Workbench

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

Saving data to a database is ideal for repeating or structured data, such as contact information. This class assumes that you are familiar with SQL databases in general and helps you get started with SQLite databases on Android. The APIs you'll need

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

本篇体验使用SQL Database Migration Wizard(SQLAzureMW)将SQL Server 2008数据库迁移到 Azure SQL Database.当然,SQLAzureMV还可以把SQL Server 2005/2012/2014迁移到Azure SQL Database. SQLAzureMV有几个版本:1.SQLAzureMW v3x 适用于 .NET Framework 3.5 和 SQL Server 2008 R2 SP1 2.SQLAzureMW v4

Using ROW_NUMBER() to paginate your data with SQL Server 2005 and ASP.NET

Jason Witty, 20 Nov 2005 4.67 (23 votes)Rate: vote 1vote 2vote 3vote 4vote 5With the release of SQL Server 2005, Microsoft introduces the long overdue ROW_NUMBER() function. In this article, we will walk through a C# implementation of pagination usin

[MSSQL2008]Spatial Data in SQL Server 2008 - 根据经纬度计算两点间距离

DECLARE @BJ GEOGRAPHY DECLARE @XT GEOGRAPHY /*     GET Latitude/Longitude FROM here:http://www.travelmath.com/cities/Beijing,+China     the distance unit in SRID 4326 is the meter */ SELECT @BJ = geography::Point('39.92889', '116.38833', 4326) SELECT

SQL data reader reading data performance test

/*Author: Jiangong SUN*/ As I've manipulated a lot of data using SQL data reader in recent project. And people says it's not good to access the data by column name. So I've made an performance test in reading data from SQL data reader. Firstly, I've

Migrating Oracle on UNIX to SQL Server on Windows

Appendices Published: April 27, 2005 On This Page Appendix A: SQL Server for Oracle Professionals Appendix B: Getting the Best Out of SQL Server 2000 and Windows Appendix C: Baselining Appendix D: Installing Common Drivers and Applications Installing

Spark1.1.0 Spark SQL Programming Guide

Spark SQL Programming Guide Overview Getting Started Data Sources RDDs Inferring the Schema Using Reflection Programmatically Specifying the Schema Parquet Files Loading Data Programmatically Configuration JSON Datasets Hive Tables Performance Tuning

SQL Source Control

https://documentation.red-gate.com/display/SOC5/SQL+Source+Control+5+documentation Working with migration scripts What are migration scripts? To deploy changes from version control, the SQL Compare engine generates a deployment script. This is based