Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Bulk Insert

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
Can SQL Bulk Insert append the rows to a table or if not, what other option do I have?
 
Thanks for the reply. I should have added this the first post:

This is my code. What do I need to change to make it append

Code:
BULK
INSERT dbo.Leads
FROM 'c:\leads.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
--Check the content of the table.
SELECT *
FROM dbo.Leads
GO
--Drop the table to clean up database.
SELECT *
FROM dbo.Leads
GO
 
I just tested that Bulk Insert does an append, and it does. Here's what I did:

I created a file like this, and saved it to C:\Colors.csv
[tt][blue]
1,Yellow
2,green
3,red
[/blue][/tt]

In a database:
Code:
Create Table Colors(ID int, Color VarChar(20))

Insert Into Colors(ID, Color) Values(7,'Blue')

And then...
Code:
BULK
INSERT dbo.Colors
FROM 'c:\Colors.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)

Now, when I select the data, it looks like this:
[tt][blue]

ID Color
----------- --------------------
7 Blue
1 Yellow
2 green
3 red
[/blue][/tt]

As you can see, it has the one row that existed prior to the import and it also has the 3 rows that were included in the csv file.

Since you are having problems with this, there must be something else going on.

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top