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

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

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

2024-08-31 00:53:13
字體:
來源:轉載
供稿:網友
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
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 涞源县| 东辽县| 石景山区| 德庆县| 连江县| 沙田区| 福清市| 枝江市| 湖北省| 富川| 兴城市| 体育| 师宗县| 潼关县| 咸宁市| 黄大仙区| 肥乡县| 清河县| 黎川县| 集安市| 江口县| 新干县| 六盘水市| 乐平市| 穆棱市| 三穗县| 开封县| 安图县| 贵溪市| 石阡县| 舞钢市| 额敏县| 重庆市| 麻阳| 江孜县| 湘潭市| 芜湖市| 九江县| 县级市| 河西区| 渑池县|