|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 3:55 AM
Points: 13,381,
Visits: 25,165
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, May 08, 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...
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, May 08, 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.
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Saturday, February 02, 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.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, June 02, 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
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, March 05, 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.
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, February 20, 2013 3:18 AM
Points: 573,
Visits: 95
|
|
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
|
|
|
|
|
Forum 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...
|
|
|
|
|
Grasshopper
      
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.
|
|
|
|
|
Forum 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
|
|
|
|