Create TestTable
USE TestData
GO
CREATE TABLE CSVTest
(ID INT,
FirstName VARCHAR(40),
LastName VARCHAR(40),
BirthDate SMALLDATETIME)
GO
Create CSV file in drive C: with name csvtest.txt with following content. The location of the file is C:\csvtest.txt
1,James,Smith,19750101
2,Meggie,Smith,19790122
3,Robert,Smith,20071101
4,Alex,Smith,20040202
Now run following script to load all the data from CSV to database table. If there is any error in any row it will be not inserted but other rows will be inserted.
BULK
INSERT CSVTest
FROM 'c:\csvtest.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
--Check the content of the table.
SELECT *
FROM CSVTest
GO
--Drop the table to clean up database.
SELECT *
FROM CSVTest
GO
http://bullpeng.tistory.com/archive/20110711
반응형
'Database > Mysql' 카테고리의 다른 글
[Mysql] 콘솔 화면에서 데이터베이스, 테이블 생성하기 : db query 문 (0) | 2011.11.20 |
---|---|
[Mysql] root의 계정 외부접속 허용하기 (0) | 2011.11.19 |
[Mysql] Illegal operation on empty result set. (0) | 2011.11.18 |