Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Mass Insert Statement

Author  Topic 

jcb267
Constraint Violating Yak Guru

291 Posts

Posted - 2009-01-19 : 19:26:08
I would like to insert 10,000 rows of data into a table. I am using this: insert into tblRiderA (MunicName, ProvName, GroupAB, Period, LocalSeed, CrtlNum, RiderASigned, SupportInc, Notes)
values ('Bancroft','Downeast EMS','A','3',$65.01,1.00,'Y','Y') for each record. Is there an easier way to commit the to the database all at once?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-19 : 20:01:05
The best way would be to have your data in a file and then use BULK INSERT to get it into the table. Barring that, you could use INSERT INTO/SELECT UNION ALL if you wanted to do it in one command but I certainly wouldn't recommend it.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

jcb267
Constraint Violating Yak Guru

291 Posts

Posted - 2009-01-19 : 20:45:35
NO, IT IS WAY TOO LONG FOR THAT. I AM GOING TO TRY BULK INSERT, I HAVE NEVER USED IT.
quote:
Originally posted by tkizer

The best way would be to have your data in a file and then use BULK INSERT to get it into the table. Barring that, you could use INSERT INTO/SELECT UNION ALL if you wanted to do it in one command but I certainly wouldn't recommend it.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


Go to Top of Page

jcb267
Constraint Violating Yak Guru

291 Posts

Posted - 2009-01-19 : 20:54:49
can you please help me with the bulk insert syntax?

this is what I have so far:
bulk insert into tblRiderA (MunicName, ProvName, GroupAB, Period, LocalSeed, CrtlNum, RiderASigned, SupportInc, Notes)
file C:\Documents and Settings\jboucher\My Documents\SQL Server Management Studio\Projects\EMS\Rider A.txt

quote:
Originally posted by tkizer

The best way would be to have your data in a file and then use BULK INSERT to get it into the table. Barring that, you could use INSERT INTO/SELECT UNION ALL if you wanted to do it in one command but I certainly wouldn't recommend it.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-19 : 21:58:25
Please check SQL Server Books Online for this.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2009-01-20 : 07:22:16
You might find it easier to use bcp for a one off insert like this. With Bulk Insert the database server has to be able to see the file (via UNC path). With BCP it's the other way around -- you have to be able to get to the server from your PC (which you already can) and there doesn't have to be a UNC path to the file for the server. The syntax is similar to bulk insert.

Here's the relevant pages for 2005:

BCP (2005) : http://msdn.microsoft.com/en-us/library/ms162802(SQL.90).aspx

BULK INSERT (2005) : http://msdn.microsoft.com/en-us/library/ms188365(SQL.90).aspx

Good luck.


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

jcb267
Constraint Violating Yak Guru

291 Posts

Posted - 2009-01-20 : 08:48:10
I DID.
quote:
Originally posted by tkizer

Please check SQL Server Books Online for this.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-20 : 08:48:55
quote:
Originally posted by jcb267

I DID.
quote:
Originally posted by tkizer

Please check SQL Server Books Online for this.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog





and did you manage to sort it out?
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2009-01-20 : 08:57:46
Why not post what you have tried so far and the particulars of your setup. Where is the file in relation to the database. What format is it in. How far have you progressed? What errors are you running into?

Then we can help you.


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -