Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7438669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:35:26+00:00 2026-05-29T10:35:26+00:00

I have an XML structure like the following: <tables> <table name=tableName1> <row ID=34 col1=data

  • 0

I have an XML structure like the following:

<tables>
  <table name="tableName1">
    <row ID="34" col1="data" col2="dom" />
    <row ID="35" col1="data2" col2="dom2" />
  </table>
  <table name="tableName2">
    <row ID="1" col1="data" col2="dom" col3="item1" />
    <row ID="3" col1="data2" col2="dom2" col3="item2" />
    <row ID="7" col1="data4" col3="item3" />
  </table>
  ...
<tables>

Basically the table nodes contain RAW data created by selecting FOR XML RAW.

Now I wish to do the reverse: read the XML and insert data into respective tables of a SQL Server 2008 R2 database. However I want the loading process to be robust, meaning I do not want to mess with column names and table names if they change in the future. I need the process to read table names from @name attributes of table nodes and insert data into columns specified by attributes in <Row> nodes. I thought of a stored procedure that gets an XML as input and does the rest.

The amount of data is approx. 70 tables ranging from 10 to 30 000 rows, altogether no more than 100 000 rows. I need to do it as efficiently as possible, bulk loading would be the best.

The process should not take care of foreign keys as the order of tables inside the XML is built so that FK constraints can be kept in place by loading one table after the other.

However there are identity columns in each table so I must do a

SET Identity_Insert ON and SET Identity_Insert OFF

before and after processing each table. I also need to reseed each table after inserting all rows. Oh,and I need to do the whole shebang in a transaction so that I could roll back if something goes wrong.

Which way do you suggest I go: should I stay with T-SQL or try to write the SP in CLR SQL? Should I use XQuery or can I use some bulk insert method?

Thanks for all the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:35:26+00:00Added an answer on May 29, 2026 at 10:35 am

    As you are dealing with fairly big XML documents, I recommend at this point to use a .net shredder. You can do that in a CLR procedure or an external tool. You could also use the build in xquery of SQL Server, but that will be slow.

    However, looking at this and your previous question (Dump data into single XML file from MS SQL Server 2008 R2), I am thinking you might be better of using something like the BCP utility or even replication. What are your exact requirements?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml file with following structure: <table name=tblcats> <row> <Id>3680</Id> <Industry>Associations</Industry> <ParentId>1810</ParentId>
I have an XML structure like the following <root> <person> <name>James</name> <description xsi:type=me:age>12</description> <description
I have a XML structure like the following: <Root> <Node Name=File System> <Node Name=C:\Windows\System32\drivers\etc\hosts>
I have xml structure like this: <Group id=2 name=Third parentid=0 /> <Group id=6 name=Five
I have the following XML structure: <agencies> <city> <name>New York</name> <address>Street A, 101</address> <phone>111-222-333</phone>
I have an XML structure like the following: <Root> <Base> <Greeting>Base Hello!</Greeting> <SpecialMessage>Base Special
I currently have an XML Structure that looks something like this <Parent> <Info> <Info-Data></Info-Data>
I have an XML Structure like the following: <Tickets> <EventsPoints> <Event ID=23> <PerformanceName>U2</PerformanceName> <EventDate>25/05/2012</EventDate>
I have an XML structure like this: <?xml version=1.0 encoding=utf-8?> <categories version=2.0> <category> <name>cat1</name>
I have the following XML structure, and I would like to have code that:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.