We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Adding data to a table

redbaron082997
on
Medium Priority
205 Views
Last Modified: 2010-03-19
What is the quickest way to add data to an sql table. In jet, I would do the following
do while !eof(source)
tbl.addnew
tbl!fld1 = data1
tbl!fld2 = data2
tbl.update
loop

I am not sure how to do this in SQL efficiently. I am doing it with a SQL RDO and opening an rdoresultset, and using the same procedure outlined above, but it is **very** slow.  I am not sure what direction to take.
Comment
Watch Question

Database Director
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Victor SpiridonovDatabase Director

Commented:
You do not need to open recorset to do that you can execute it as pass-through query.

Author

Commented:
Ok, but how would it work in a scenario that I am reading a text file (warning* it is very huge. Every day I am adding 100,000 records), and adding those values, to the table?
right now, I do the following
readNextLine( inFile,InText)
db.addnew
db.fld1 = getfld(1,inText)
db.fld2 = getfld(2,intext)
etc..
db.update

I am increasing the points. Thanks

Author

Commented:
Would a stored procedure be worth it? Since this is a task that is done every single day, and generally the information that needs to be added is available only 1 hr before the time that it is needed,I need to optimize everything!!! Thanks
Victor SpiridonovDatabase Director

Commented:
If you are reading from text file you should look at using bcp programm which is designed to load text data into SQL server it is console (text) mode program and it will be the fastest solution to use , much faster then any insert.

Author

Commented:
I have been looking at that ,and you are right. Much faster. Is there any way to implement this kind of speed without using BCP? are the SQL calls available to VB that BCP is using?
Victor SpiridonovDatabase Director

Commented:
BCP is using a set of DB-library functions created specificly for the  purpose of loading text files,I'm not sure if you can use them from VB. You probably should ask such question in VB area.

Author

Commented:
Thanks for the help!!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.