SQL Server使用Bulk Insert把一个文本导入到数据库
2009-11-19 10:02
573 查看
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
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.
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
相关文章推荐
- SQL Server使用Bulk Insert把一个文本导入到数据库--http://www.wangchao.net.cn/it/detail_59013.html
- 使用 BULK INSERT 或 OPENROWSET(BULK...) 导入批量数据 (SQL Server)
- BULK INSERT如何将大量数据高效地导入SQL Server
- mysql中如何使用一句话将一个表的数据导入到另一个表中:insert into ...select
- Excel导入数据到Sql server 中出错:“文本被截断,或者一个或多个字符在目标代码页中没有匹配项”
- 使用 BULK INSERT 或 OPENROWSET(BULK...) 导入大容量数据
- SQL Server中采用BULK INSERT实现大数据量文本文件批量导入
- SQL Server中采用BULK INSERT实现大数据量文本文件批量导入
- SQL Server中采用BULK INSERT实现大数据量文本文件批量导入
- SQL Server中采用BULK INSERT实现大数据量文本文件批量导入
- Excel导入数据到Sql server 中出错:“文本被截断,或者一个或多个字符在目标代码页中没有匹配项”
- BULK INSERT, 实战手记:让百万级数据瞬间导入SQL Server
- 使用BULK INSERT高效导入大量数据到SQL Server数据库
- SQL Server中采用BULK INSERT实现大数据量文本文件批量导入
- BULK INSERT如何将大量数据高效地导入SQL Server
- SQL Server 2005使用SCP文本导入导出数据
- BULK INSERT如何将大量数据高效地导入SQL Server
- sql server 导入平面文件源数据,错误 0xc02020a1错误 0xc020902a 错误 0xc02020c5,返回状态值 4 和状态文本“文本被截断,或者一个或多个字符在目标代码页...
- BULK INSERT如何将大量数据高效地导入SQL Server
- SQL Server数据导入导出工具BCP使用详解