Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import pipe delimited text file data to SQLServer table

I have database table represented as text file in the following pattern:

0|ALGERIA|0| haggle. carefully f|
1|ARGENTINA|1|al foxes promise|
2|BRAZIL|1|y alongside of the pendal |
3|CANADA|1|eas hang ironic, silent packages. |

I need to import this data to a SQL Server 2008 database table. I have created the table with the types matching the schema.

How to import this data to the table?

EDIT: Solved by following the answer selected. Note to anyone stumbling upon this in future: The datatype needs to be converted. Refer: http://social.msdn.microsoft.com/Forums/en/sqlintegrationservices/thread/94399ff2-616c-44d5-972d-ca8623c8014e

like image 861
softwarematter Avatar asked Feb 11 '11 08:02

softwarematter


2 Answers

You could use the Import Data feature by right mouse clicking the database, and then clicking Tasks then Import Data. This will give you a wizard which you can specify the delimiters etc. for your file and preview the output before you've inserted any data.

like image 74
Neil Knight Avatar answered Oct 20 '22 00:10

Neil Knight


If you have a large amount of data you can use bcp to bulk import from file: http://msdn.microsoft.com/en-us/library/ms162802.aspx

The bcp utility bulk copies data between an instance of Microsoft SQL Server and a data file in a user-specified format. The bcp utility can be used to import large numbers of new rows into SQL Server tables... Except when used with the queryout option, the utility requires no knowledge of Transact-SQL. To import data into a table, you must either use a format file created for that table or understand the structure of the table and the types of data that are valid for its columns.

like image 36
Kris C Avatar answered Oct 20 '22 00:10

Kris C