Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Inserting Records into SQL Server - is there a faster interface than ADO

Reply
Thread Tools

Inserting Records into SQL Server - is there a faster interface than ADO

 
 
geskerrett@hotmail.com
Guest
Posts: n/a
 
      11-11-2005
I have a program that reads records from a binary file and loads them
into an MS-SQL Server database. It is using a stored proc, passing the
parameters.

I am using pywin32 to create a connection object. Once the connection
is open I simple pass the SQL formatted commands using
cnx.Execute(sqlstring).

My test examples;

20,000 records using the ADO connection: 0:04:45:45

If I setup the program to not send the record to the database - so all
other variables and processes are constant, it simply just skips the
cnx.Execute(sqlstring) step, then it takes only 0:00:25:78 to process
thru the same number of trx.

Obviously the times in my test are that , but I have a client that woud
like to use this and has several million transactions to content with.

So my questions is ....
Is there a "faster" method I can use to connect to the SQL server ?
Or does anyone have any "optimization" tips the can offer ?

 
Reply With Quote
 
 
 
 
Jarek Zgoda
Guest
Posts: n/a
 
      11-11-2005
napisał(a):

> Is there a "faster" method I can use to connect to the SQL server ?
> Or does anyone have any "optimization" tips the can offer ?


This has nothing with python, but the fastest way to load large amount
of data to MS SQL Server database is DTS import from flat file.

To spped up the things a bit, do not commit transaction after each row
inserted -- commit whole batch.

--
Jarek Zgoda
http://jpa.berlios.de/
 
Reply With Quote
 
 
 
 
Alan Kennedy
Guest
Posts: n/a
 
      11-11-2005
[]
> I have a program that reads records from a binary file and loads them
> into an MS-SQL Server database. It is using a stored proc, passing the
> parameters.


[snip]

> So my questions is ....
> Is there a "faster" method I can use to connect to the SQL server ?
> Or does anyone have any "optimization" tips the can offer ?


Is there a reason why you need to use a stored procedure?

Do you need to process the data in some way in order to maintain
referential integrity of the database?

If the answer to both these questions is "no", then you can use the
"bcp" (Bulk CoPy) utility to transfer data into SQLServer *very* quickly.

http://msdn.microsoft.com/library/en...p_bcp_61et.asp
http://www.sql-server-performance.com/bcp.asp

thought-it-was-worth-mentioning-ly y'rs,

--
alan kennedy
------------------------------------------------------
email alan: http://xhaus.com/contact/alan
 
Reply With Quote
 
Scott David Daniels
Guest
Posts: n/a
 
      11-11-2005
Alan Kennedy wrote:
> []
>
>> I have a program that reads records from a binary file and loads them
>> into an MS-SQL Server database. It is using a stored proc, passing the
>> parameters.

>
>> So my questions is ....
>> Is there a "faster" method I can use to connect to the SQL server ?
>> Or does anyone have any "optimization" tips the can offer ?

>
> Is there a reason why you need to use a stored procedure?
>
> Do you need to process the data in some way in order to maintain
> referential integrity of the database?
>
> If the answer to both these questions is "no", then you can use the
> "bcp" (Bulk CoPy) utility to transfer data into SQLServer *very* quickly.
>
> http://msdn.microsoft.com/library/en...p_bcp_61et.asp
> http://www.sql-server-performance.com/bcp.asp
>
> thought-it-was-worth-mentioning-ly y'rs,
>

If the answer to some of the earlier questions is "yes," I have
found "bcp" can be a great tool to fill up a new table of data
"on its way in." SQL can then move it to where it should really
go with nice transaction-protected SQL, proper index-building
and so on. After distributing the data, you can drop the table
of pending data.

I agree this is off-topic, but it is too close to my experience.

--Scott David Daniels

 
Reply With Quote
 
geskerrett@hotmail.com
Guest
Posts: n/a
 
      11-14-2005
The utility is designed to run in the background and maintain/update a
parallel copy of a production system database. We are using the
stored procedure to do a If Exist, update, else Insert processing for
each record.

The originating database is a series of keyed ISAM files. So we need
to read each record, perform some simple data conversions and then
update the SQL database. We are using Python to read the originating
database and perform the record conversion and then posting the results
back to SQL Server.

We designed our utility to run a night so that the SQL server is up to
date the next day and ready for reporting.

Thanks for your tips on BCP. I will investigate further as it looks
like it might be useful for the initial loading of the data and perhaps
some changes to the our utility program to minimize the amount of data
that needs to be read/processed.

Geoff.

 
Reply With Quote
 
Oren Tirosh
Guest
Posts: n/a
 
      11-14-2005
> We are using the stored procedure to do a If Exist, update, else Insert processing for
> each record.


Consider loading the data in batches into a temporary table and then
use a single insert statement to insert new records and a single update
statement to update existing ones. This way, you are not forcing the
database to do it one by one and give it a chance to aggressively
optimize your queries and update the indexes in bulk. You'd be
surprized at the difference this can make!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a page for inserting new records into a SQL Server 2000 DB newt039@gmail.com ASP .Net 0 01-26-2007 09:33 PM
Problem (Inserting records into sql server 2000 using asp.net) =?Utf-8?B?UCBvZiBEaHVtcA==?= ASP .Net 2 08-18-2005 03:29 PM
Inserting records into 2 identical fields at once (???) Chumley the Walrus ASP .Net 1 08-12-2004 05:40 PM
Inserting dates into SQL Server DB Andrew Banks ASP .Net 11 01-07-2004 12:24 AM
How to retrieve the records if I have .SQL script file using ADO.net Kiran ASP .Net Datagrid Control 4 10-14-2003 08:38 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57