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
 How to bulk insert from a txt file?

Author  Topic 

mr_2
Starting Member

2 Posts

Posted - 2008-03-28 : 07:08:42
Well hi here is my text file
"Kelly","Reynold","kelly@reynold.com"
"John","Smith","bill@smith.com"
"Sara","Parker","sara@parker.com"


and a table with Id , name, surname, email

the ID is a autoincrement thats why it gives me error any way to to skip this ID so let the sql create it automaticaly for every row?

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-03-28 : 07:19:35
Which tool/method you are using to import the file?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

mr_2
Starting Member

2 Posts

Posted - 2008-03-28 : 07:54:10
I am using sql 2005 bellow is my query

bulk insert dbo.info from 'C:\test\1.txt' with (FIELDTERMINATOR = '","', ROWTERMINATOR = '\n')
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2008-03-28 : 08:28:15
Your fieldterminator won't work for a quote delimited data.
Have a look at
http://www.nigelrivett.net/SQLTsql/BCP_quoted_CSV_Format_file.html
It shows how to use a format file to import quoted data.

As to the identity - you can use the format file but it's often easier to create a view that excludes it and bcp into that. If you need a format file anyway then you might as well use that but I try to avoid them if possible.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -