Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««123»»

Using OpenXML Expand / Collapse
Author
Message
Posted Thursday, May 12, 2005 11:28 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 12:07 PM
Points: 15,562, Visits: 27,940
That's good to know. We were doing it for performance reasons, not because of failures in the code, but if we dodged a bullet, so much the better.

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #181978
Posted Friday, May 13, 2005 4:11 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, May 8, 2013 7:23 AM
Points: 199, Visits: 136

Tricky one...

i m working on it ... wait for some time

Are you in need of a generic stored proc. (to insert data in any table) ???

If not, then solution is simple...

Post #182162
Posted Friday, May 13, 2005 4:19 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, May 8, 2013 7:23 AM
Points: 199, Visits: 136

nice suggestion for using temp tables...

Its better to use them if the XML files are large...

If any exceptions occurs, temporary tables are not destroyed from the memory.

This can be a big problem.

Instead, one can use variable of TABLE Type.

thnx.

Post #182166
Posted Friday, May 13, 2005 8:21 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Saturday, February 2, 2013 8:21 AM
Points: 283, Visits: 268
Well, if you can make it for one table, I can probably modify the Proc to handle any table. Also, I can have the Proc auto-magically figure out the PKeys for the Table it's importing, so don't worry about that either.


Post #182265
Posted Thursday, June 2, 2005 3:47 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, June 2, 2005 3:46 AM
Points: 1, Visits: 1

Good job.

But in practical scenario where we have a huge data, say 2,000,000 records to be inserted into the database, the OpenXML command doesnt seem to be satisfactory.We are facing this problem where we have used this OpenXML which consumes about 15secs for inserting 65,000 records in a single user environment.When it is concurrent users, the performance of the entire system is poor.

We came across another component 'XML Bulk Load Component' for the same scenario.But wasnt able to proceed much on this.Would like to have comments from anyone who have knowledge on this.

Thanks & Regards,

Ramya

Post #186918
Posted Thursday, June 9, 2005 9:31 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, March 5, 2009 10:48 AM
Points: 1, Visits: 2
I don't understand the benefit outlined in the introduction.
 
Even with SQL 6.5 you could have simply submitted the 100 insert statements in one big string and executed it (ADO/ASP/.Net has supported this for years). 1 trip, 100 records. The extra T-SQL involved should be the same size as the extra XML tags involved.
 
i.e. cn.execute "INSERT Table VALUES ('Jim') INSERT Table VALUES ('Bob')"
 
The non-XML method should also be easier because you don't need to figure out how to transfer the xml file to the other server (assuming the sql server was on a different machine then your code). Transferring one XML file is easy. Transferring multiple XML files due to multiple users/threads will have implications (not to mention cleanup). Why bother when there is no benefit?
 
Of course, if you really needed to insert a LOT of records you wouldn't use either of these methods.
Post #189348
Posted Tuesday, February 21, 2006 3:44 PM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, March 13, 2014 10:40 AM
Points: 573, Visits: 107

If you are interested in using OPENXML I strongly suggest that you get hold of a copy of SQL Server XML Distilled. Why you may ask, well I wrote the OPENXML chapter. It covers, the pros and cons of element and attribute centric documents. Performance of using OPENXML relating to document size, attributes, namespaces.

There are lots of gotchas to be wary of, type casting, nulls, case sensitivity, use of complex xpath.

I also investigate the memory issue, its not as cut and dried as the 1/8th statement suggests, and generally depends on available memory at startup

You can't pass in a filename, but in 2005 you can read the contents of a file into an xml variable and then use that.

Passing the XML document to the SQL server is just the same as passing any other text. exec up_myXMLProc '<root><element1></element1> ....</root>', No clean up is neccesary except the use of sp_xml_removedocument, which should be called after every openxml call.

As for the benefits, the one is the saving of hierachical data, you only have to make one SP call rather than one for the parent and one for each child. These can be batched up which is why in testing both ways work out to be pretty much the same.

In 2005 the parser has been updated so you can use more xpath functions, in addition you can use xquery.

So lots of good things.




Simon Sabin
SQL Server MVP

http://sqlblogcasts.com/blogs/simons
Post #260427
Posted Tuesday, April 4, 2006 8:03 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, May 31, 2007 3:44 AM
Points: 1, Visits: 1

hi,  

    Using Open XML was a article full of information. It was partucurly helpful for me because ur simple and easy to understand presentation.keep posting...

Post #270855
Posted Friday, May 12, 2006 1:04 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, June 13, 2006 7:56 AM
Points: 11, Visits: 1

Very good, well orgainzed article with everything needed for simple XML queries.

But it seems to me that responsible developers should avoid the temptation to use new technologies simply because of their cool value. XML has its uses for hierarchical representation of data and as a communication format for web applications (because of firewall transparency).

However, for the examples provided in the original article, the equivalent code in T/SQL is much simpler and does not require the use of Temp tables (and thus tempdb) or table variables which have their own particular limitations.

In addition, for SQL Server 2000 applications XML is not optimized by the query optimizer and thus can be a performance liability depending on the complexity of the query. I don't know about 2005, but I assume that it's implementation is similar though query syntax is greatly simplified.

I would simply advise anyone thinking of using XML in SQL Server 2000 to do so for the right reasons and ensure that their code remains efficient, readable and maintainable.

 

Post #279775
Posted Friday, October 6, 2006 12:29 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, August 15, 2007 12:12 AM
Points: 4, Visits: 1
good article vasant You done a nice job
Post #313742
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse