Home Products Support Sales Corporate
Products
Performance Monitor
Database Compare
Database Manager
Job Scheduler






Home > Articles > SQL Server Development & T-SQL > BULK INSERT Data into a SQL Server Table from a CSV file

BULK INSERT Data into a SQL Server table from a CSV file



BULK INSERT Data into a SQL Server Table from a CSV fileYou want to import your sales orders from a comma delimited file into a SQL Server or MSDE table called orders. The file looks like this:

345,John Doe, 400
346,Mark Smith,450
347,Robert,400

 

Run the following SQL command from the SQL window in Teratrax Database Manager. Replace lower case text with your own:

BULK INSERT [orders]
FROM 'c:\orders.csv'
WITH (FIELDTERMINATOR = ',')

 

Result (order table):
OrderID Name Price
345 John Doe 400
346 Mark Smith 450
347 Robert 400

 

 

 

 

Make sure the field terminator (',' in this example) is not part of any actual value. The field Name for instance cannot be 'Doe, John' since the ',' would be considered as a field terminator.

The table has to be similar in format to the file (same number of fields and same data type.)

 



Tools

Troubleshoot SQL Server Performance


Compare and Sync SQL Server Databases


Import & Export SQL Server Data


Schedule SQL Server Express Backups







Articles

Advantages of SQL Server 64-bit


Understanding SQL Server Blocking & Deadlocks


SQL Server Memory Internals

Privacy Statement License Agreement Articles Site Map         Copyright © 2002-2010 Teratrax Inc. All rights reserved.