BULK INSERT Data into a SQL Server table from a CSV file
You
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.)
|