Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

BULK insert

 
   Database Help (Home) -> Programming RSS
Next:  Help Optimising SQL  
Author Message
lord.fist

External


Since: Dec 12, 2006
Posts: 12



(Msg. 1) Posted: Wed Jan 03, 2007 10:26 pm
Post subject: BULK insert
Archived from groups: microsoft>public>sqlserver>programming (more info?)

I am trying to do bulk insert 5000 rows into a simple table that has:

id pk identity, col_text nvarchar(500)

How do i do bulk insert but to only insert data that is not duplicated
eg. if i have already in table 'some_text' and bulk inserting
'some_text' that the text is not inserted and all other is?

 >> Stay informed about: BULK insert 
Back to top
Login to vote
Alex Kuznetsov

External


Since: Sep 29, 2006
Posts: 239



(Msg. 2) Posted: Wed Jan 03, 2007 10:26 pm
Post subject: Re: BULK insert [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

lord.fist wrote:
> I am trying to do bulk insert 5000 rows into a simple table that has:
>
> id pk identity, col_text nvarchar(500)
>
> How do i do bulk insert but to only insert data that is not duplicated
> eg. if i have already in table 'some_text' and bulk inserting
> 'some_text' that the text is not inserted and all other is?

Bulk insert all your data into a staging table. Insert only the rows
you want using a regular INSERT command wiht WHERE NO EXISTS() clause.

-----------------------
Alex Kuznetsov
http://sqlserver-tips.blogspot.com/
http://sqlserver-puzzles.blogspot.com/

 >> Stay informed about: BULK insert 
Back to top
Login to vote
Alex Kuznetsov

External


Since: Sep 29, 2006
Posts: 239



(Msg. 3) Posted: Wed Jan 03, 2007 10:26 pm
Post subject: Re: BULK insert [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

lord.fist wrote:
> Alex Kuznetsov wrote:
> > lord.fist wrote:
> >> I am trying to do bulk insert 5000 rows into a simple table that has:
> >>
> >> id pk identity, col_text nvarchar(500)
> >>
> >> How do i do bulk insert but to only insert data that is not duplicated
> >> eg. if i have already in table 'some_text' and bulk inserting
> >> 'some_text' that the text is not inserted and all other is?
> >
> > Bulk insert all your data into a staging table. Insert only the rows
> > you want using a regular INSERT command wiht WHERE NO EXISTS() clause.
>
>
> How fast will that actualy be? Since i need to insert data every 5-10min...

Try it out - 5K rows is a very small amount in most environments.

-----------------------
Alex Kuznetsov
http://sqlserver-tips.blogspot.com/
http://sqlserver-puzzles.blogspot.com/
 >> Stay informed about: BULK insert 
Back to top
Login to vote
lord.fist

External


Since: Dec 12, 2006
Posts: 12



(Msg. 4) Posted: Wed Jan 03, 2007 10:43 pm
Post subject: Re: BULK insert [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Alex Kuznetsov wrote:
> lord.fist wrote:
>> I am trying to do bulk insert 5000 rows into a simple table that has:
>>
>> id pk identity, col_text nvarchar(500)
>>
>> How do i do bulk insert but to only insert data that is not duplicated
>> eg. if i have already in table 'some_text' and bulk inserting
>> 'some_text' that the text is not inserted and all other is?
>
> Bulk insert all your data into a staging table. Insert only the rows
> you want using a regular INSERT command wiht WHERE NO EXISTS() clause.


How fast will that actualy be? Since i need to insert data every 5-10min...
 >> Stay informed about: BULK insert 
Back to top
Login to vote
Erland Sommarskog2

External


Since: May 30, 2004
Posts: 2061



(Msg. 5) Posted: Wed Jan 03, 2007 11:24 pm
Post subject: Re: BULK insert [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

lord.fist (lord.fist@spam.email.htnet.hr) writes:
> I am trying to do bulk insert 5000 rows into a simple table that has:
>
> id pk identity, col_text nvarchar(500)
>
> How do i do bulk insert but to only insert data that is not duplicated
> eg. if i have already in table 'some_text' and bulk inserting
> 'some_text' that the text is not inserted and all other is?

If you are on SQL 2005 you can use OPENROWSET(BULK) and then apply filters
to the data.

Else you will have to do as Alex said, and go by a staging table. If you
are only importing 5000 rows every five minutes, I would not worry about
the load.


--
Erland Sommarskog, SQL Server MVP, esquel.RemoveThis@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
 >> Stay informed about: BULK insert 
Back to top
Login to vote
lord.fist

External


Since: Dec 12, 2006
Posts: 12



(Msg. 6) Posted: Fri Jan 05, 2007 1:18 am
Post subject: Re: BULK insert [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Erland Sommarskog wrote:
> lord.fist (lord.fist@spam.email.htnet.hr) writes:
>> I am trying to do bulk insert 5000 rows into a simple table that has:
>>
>> id pk identity, col_text nvarchar(500)
>>
>> How do i do bulk insert but to only insert data that is not duplicated
>> eg. if i have already in table 'some_text' and bulk inserting
>> 'some_text' that the text is not inserted and all other is?
>
> If you are on SQL 2005 you can use OPENROWSET(BULK) and then apply filters
> to the data.
>
> Else you will have to do as Alex said, and go by a staging table. If you
> are only importing 5000 rows every five minutes, I would not worry about
> the load.
>
>

Ok thank you all for help!
 >> Stay informed about: BULK insert 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Bulk insert problem - Hi! I have done bcp out using -V and -q switch from one table and using only -V switch on another table on the server running on sql server 2000. the datatype used is native i.e. -n switch. When I am trying to import it using BCP IN in the server..

Permissions and Bulk Insert - SS2005. I have a need for users to BULK INSERT files on an adhoc basis. Basically they want to upload a file and have immediate access. Right now, I'm doing that by assigning those users to the bulkadmin server role, and having them call a procedure..

Bulk Insert into New Table - I'm trying to Bulk Insert data but the table has yet to be created. I don't know what the definition of the table should be so the data imports without a hitch. Any suggestions?

bulk insert and openrowset - i'm having the strangest problem right now and can't seem to figure out what's going on- here's the deal: i'm trying to use the openrowset command, in combination with the bulk insert command to load data from a text file into sql server. the text..

block Bulk insert - Hi, I was asked at a job interview to create a trigger that will block the bulk insert in a table. I HAVE NO IDEA OF HOW TO BLOCK BULK INSERT!! Any ideas? Thanks, Carly
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]