SQL Server使用Bulk Insert把一个文本导入到数据库
作者 佚名技术
来源 数据库编程
浏览
发布时间 2012-03-22
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 |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
上一篇: 学习SQL2005当中的例子下一篇: 开发环境下优化SQl语句的十个重要步骤
关于SQL Server使用Bulk Insert把一个文本导入到数据库的所有评论