SQL SERVER - Import CSV File Into SQL Server Using Bulk Insert - Load Comma Delimited File Into SQL Server
2008-02-08 07:39
661 查看
February 6, 2008 by pinaldave
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 TestTableUSE 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.
DROP TABLE CSVTest GO
相关文章推荐
- SQL SERVER – Import CSV File Into SQL Server Using Bulk Insert – Load Comma Delimited File Into SQL Server
- How do I load text or csv file data into SQL Server?
- [SQL Server][FILESTREAM] -- Using INSERT, UPDATE and DELETE to manage SQL Server FILESTREAM Data
- C# .NET - Sql Bulk Insert from multiple delimited Textfile using c#.net
- Read A Flat File Using File Layout And Insert Into The Specific Component Using CI ( Bulk Insert )
- How To Load CLOB Data from a File into a CLOB column using PL/SQL
- Import XML file into SQL Server
- Import data from files to SQL Server(用BULK INSERT命令导入数据详解)
- [SQL Server][FILESTREAM] -- Best Practices When Using FILESTREAM Feature of SQL Server 2008
- using sqlbulkcopy to quick load data from your client to sqlserver
- How to import a SQL Server .bak file into MySQL?
- Bulk Insert from Flat File Using Transact-SQL
- Import/Export Excel (.Xlsx) or (.Xls) File into SQL Server
- [转]How to Import a Text File into SQL Server 2012
- ?? [SQL Server] -- Using FILESTREAM to Store BLOBs in the NTFS File System in SQL Server 2008
- Import .bak file to a database in SQL server
- How to Insert Values into an Identity Column in SQL Server
- Could not load file or assembly 'Microsoft.SqlServer.Management.Sdk.Sfc, Version=11.0.0.0, Culture=n
- (总结) SQL Server Bulk Insert 批量数据导入
- Import UTF-8 file to SQL Server