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

首頁 > 數(shù)據(jù)庫 > SQL Server > 正文

SQL Server使用Bulk Insert把一個文本導(dǎo)入到數(shù)據(jù)庫

2019-11-03 08:35:23
字體:
供稿:網(wǎng)友
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ā)表
主站蜘蛛池模板: 酒泉市| 洪洞县| 民和| 湖北省| 壤塘县| 石屏县| 枣庄市| 桃源县| 泾源县| 安达市| 通州市| 阿坝县| 汕头市| 卓尼县| 宁夏| 琼海市| 浪卡子县| 平安县| 凤冈县| 沙坪坝区| 宜兰市| 洪泽县| 霞浦县| 桂平市| 永新县| 靖边县| 衡水市| 上蔡县| 筠连县| 黑水县| 利川市| 龙南县| 稷山县| 报价| 辛集市| 郑州市| 郑州市| 宁都县| 福建省| 安福县| 浮山县|