国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > SQL Server > 正文

SQL Server使用Bulk Insert把一個文本導入到數據庫

2024-08-31 00:53:14
字體:
來源:轉載
供稿:網友
This is very common request recently – How to import CSV file into SQL Server? How to load CSV file into SQL Server Database Table? How to load comma delimited file into SQL Server? Let us see the solution in quick steps.

CSV stands for Comma Separated Values, sometimes also called Comma Delimited Values.

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
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 电白县| 法库县| 嵊州市| 平罗县| 台中县| 瑞昌市| 锡林郭勒盟| 高邑县| 昭苏县| 灌南县| 湖州市| 偃师市| 揭东县| 安岳县| 扎鲁特旗| 简阳市| 徐汇区| 手机| 鄄城县| 嘉义市| 公安县| 庄浪县| 多伦县| 宣化县| 永康市| 阳城县| 太仆寺旗| 三江| 邯郸县| 屏东县| 石渠县| 晋城| 饶平县| 江都市| 工布江达县| 洛隆县| 桐柏县| 松潘县| 沙坪坝区| 福海县| 北海市|