Friday, October 7, 2011

Bulk Importing Data Into SQL Server

Most common and regular requests for the DBA is to import the CSV (Comma Separated Values) file into SQL Server table or load comma delimited file into SQL Server.

Please refer to the following Example for how to import CSV file into SQL Server. 

Step #1 Table Creation Script
CREATE TABLE [dbo].[Country](
    [CountryRegionCode] [nvarchar](3) NOT NULL,
    [CurrencyCode] [nchar](3) NOT NULL,
    [ModifiedDate] [datetime] NOT NULL
    GO 

Step #2  Create One CSV file. 
Create CSV file in your physical drive with name of csvfileimport.txt with following content. The location of the file is Z:\csvfileimport.csv

AE    AED    2004-03-11 10:17:21.510
AR    ARS    2004-03-11 10:17:21.510
AT    ATS    2004-03-11 10:17:21.510
AT    EUR    1998-06-01 00:00:00.000
AU    AUD    2004-03-11 10:17:21.510


Step #3 Script for bulk load into SQL Server Table
For loading the above comma delimited file to SQL Server table run below script. 
BULK
INSERT Country
FROM 'z:\csvfileimport.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO 

Step 4. Run below query to check data weather correctly imported or not? 
SELECT *
FROM Country
GO

SQL Server 2005 Import / Export Wizard. SQL Server 2008 Import / Export Wizard. SQL Server 2012 Import / Export Wizard. How to import data from Excel to SQL Server. How to import data from CSV to SQL Server. How to import data from flat file to SQL Server. How to import data from text file to SQL Server. Import CSV File Into SQL Server . Bulk importing data into SQL Server. Data Import Functionality Using SQL Server. Using DTS to Automate a Data Import Process. export data from sql server. Scheduling Data Imports in SQL Server. Using BULK INSERT to Load a Text File. SQL Bulk Insert Example. Bulk Insert into SQL Server using SqlBulkCopy. Bulk Inserts via TSQL in SQL Server. bulk insert in sql server from csv. bulk insert in oracle. bulk insert in sql server 2012 from csv. using bulk insert in sql server. bulk insert in sql from excel bulk insert in sql server 2008. how to do a bulk insert in sql server. bulk insert in sql server

0 comments:

Post a Comment