Migration data on SQL

Source: Internet
Author: User

Export the data XML from the table:

--ExportDeclare@xmlXmlSet@xml= (Select*From(Select TableName=‘Schema‘, XmlData= (Select*From[Schema]where ID=337For XML auto, root (‘Schemas‘) )UnionSelect‘Schemafile‘, (SelectId, SchemaID, Data= convert (varchar ( Span style= "color: #ff00ff;" >maxfrom Schemafile where schemaid = 337 for XML auto, root (schemafiles )) Schemaexportfor XML auto, root ( "schemaexports '  @xml           

Insert the exported XML data into the destination table:

1 --Now import2 3 Declare @idoc int4 5       Declare @tableName varchar(255)  6       Declare @xmlDataXML7       8       Declare @mappingExport Table(TableNamevarchar(255), xmlData XML)9 Ten       execsp_xml_preparedocument@idocOutput@xml One       Insert  into @mappingExport A       Select * -        fromOPENXML (@idoc,'/schemaexports/schemaexport') -        with(TableNamevarchar(255), theXmlDatanvarchar(Max)) -       execSp_xml_removedocument@idocOutput -        -       DeclareExportcursorcursor +        for SelectTableName, XmlData -        from @mappingExport +  A       OpenExportcursor at  -       Fetch  fromExportcursor into @tableName,@xmlData -  -        while @ @fetch_status <> -1 -       begin -             execsp_xml_preparedocument@idocOutput@xmlData in                    -             if(@tableName = 'Schema') to             begin +                   Print 'Copying Schema'  -  the                   Select * *                    fromOPENXML (@idoc,'/schemas/schema') $                    with(Idint,Panax NotoginsengTenantIdint, -Versionnoint, theResponseschemaidint, +SchemaNamenvarchar( $), ASoapactinovarchar( $), theLastupdatedutcdatetime, +Iscanonicalbit, -DocumentTypenvarchar( +) ) $             End $             Else if(@tableName = 'Schemafile') -             begin -                   Print 'Copying schemafile' the                   Select *,datalength(data),Convert(XML, data) -                    fromOPENXML (@idoc,'/schemafiles/schemafile')Wuyi                    with(Idint, theSchemaIDint, -Datavarchar(Max), WuFileNamenvarchar(255), -FullPathnvarchar(255), AboutRelativePathnvarchar(255) ) $             End -             execSp_xml_removedocument@idoc  -             Fetch Next  fromExportcursor into @tableName,@xmlData             -       End    A        + Select datalength(data),Convert(XML, data) the  fromSchemafile - whereSchemaID= 337

Migration data on SQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.