944,172 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Marked Solved
  • Views: 3569
  • MS SQL RSS
Oct 24th, 2009
0

Importing xml into sql server 2008

Expand Post »
Hi,

I need a little help importing an XML file into sqlserver 2008. I followed this example

http://www.sql-server-performance.co...r_2008_p1.aspx

(make sure you goto the rest of the pages in the article!) , generated the schema etc., but I can't get the import

to do what I need. I was able to add the DataConversion on my own but I can't seem to figure out how to get both ID

fields in the middle table.
I made a simplified version. For this example I have 3 tables. Books, BookAuthors, Authors.

Books Table (bookID, bookTitle, bookNumPages)
BookAuthors Table (bookID, authorID)
Authors (authorID, authorName)

After the Import the tables should look like this
Books
79, Some Good Book, 300
112, Another Book, 350
BookAuthors
79, 200
79, 205
79, 215
112, 200
Authors
200, First Author
205, Second Author
215, Third Author

The Problem I'm having is getting the BookID and AuthorID into the BookAuthors Table. I'm just wondering if there

is an easy way to set this up to Import or if I'm going to have to code it line by line.

MS SQL Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <result>
  3. <books>
  4. <book>
  5. <bookID>79</bookID>
  6. <bookTitle>Some Good Book</bookTitle>
  7. <bookNumPages>300</bookNumPages>
  8. <authors>
  9. <author>
  10. <authorID>200</authorID>
  11. </author>
  12. <author>
  13. <authorID>205</authorID>
  14. </author>
  15. <author>
  16. <authorID>215</authorID>
  17. </author>
  18. </authors>
  19. </book>
  20. <book>
  21. <bookID>112</bookID>
  22. <bookTitle>Another Book</bookTitle>
  23. <bookNumPages>350</bookNumPages>
  24. <authors>
  25. <author>
  26. <authorID>200</authorID>
  27. </author>
  28. </authors>
  29. </book>
  30. </books>
  31. <authors>
  32. <author>
  33. <authorID>200</authorID>
  34. <authorName>First Author</authorName>
  35. </author>
  36. <author>
  37. <authorID>205</authorID>
  38. <authorName>Second Author</authorName>
  39. </author>
  40. <author>
  41. <authorID>215</authorID>
  42. <authorName>Third Author</authorName>
  43. </author>
  44. </authors>
  45. </result>
Similar Threads
Reputation Points: 21
Solved Threads: 0
Newbie Poster
dvprez is offline Offline
4 posts
since Jul 2007
Oct 28th, 2009
1
Re: Importing xml into sql server 2008
4 days and no answers so I just did it myself and ending up making a blog incase someone else needs to do the same thing. You can find the solution here

http://dvprez.blogspot.com/2009/10/i...rver-2008.html
Reputation Points: 21
Solved Threads: 0
Newbie Poster
dvprez is offline Offline
4 posts
since Jul 2007
Feb 9th, 2011
0
Re: Importing xml into sql server 2008
hw do i import schema in .xml format to sql 2008 server?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
l.geetha86 is offline Offline
1 posts
since Feb 2011

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: Recover SQL server 2008 database
Next Thread in MS SQL Forum Timeline: how to convert sql server database to access database





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC