All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
SQL,Server使用Bulk,Insert把一个文本导入到数据库_mssql学习_编程技术

Writer: delv Article type: Programming skills(编程技巧) Time: 2013/12/30 4:37:14 Browse times: 389 Comment times: 0

SQL,Server使用Bulk,Insert把一个文本导入到数据库_mssql学习_编程技术


Head photo

Go homepage
Upload pictures
Write articles

SQL Server使用Bulk Insert把一个文本导入到数据库_mssql学习_编程技术-你的首页-uuhomepage.comThis 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 TestTableUSE TestDataGOCREATE TABLE CSVTest(ID INT,FirstName VARCHAR(40),LastName VARCHAR(40),BirthDate SMALLDATETIME)GOCreate CSV file in drive C: with name csvtest.txt with following content. The location of the file is C:\csvtest.txt1,James,Smith,197501012,Meggie,Smith,197901223,Robert,Smith,200711014,Alex,Smith,20040202Now 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.BULKINSERT CSVTestFROM 'c:\csvtest.txt'WITH(FIELDTERMINATOR = ',',ROWTERMINATOR = '\n')GO--Check the content of the table.SELECT *FROM CSVTestGO--Drop the table to clean up database.SELECT *FROM CSVTestGO




There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.