Home > Ask the SQL Server Experts > Roman Rehak - SQL Server Development and Reporting Services Questions & Answers > BULK INSERT to import data from file to SQL Server database
Ask The SQL Server Expert: Questions & Answers
EMAIL THIS

BULK INSERT to import data from file to SQL Server database

Roman Rehak EXPERT RESPONSE FROM: Roman Rehak

Pose a Question
Other SQL Server Categories
Meet all SQL Server Experts
Become an Expert for this site


Expert advice on database development
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


>
QUESTION POSED ON: 05 December 2007
I would like a stored procedure to import data from a .txt or .xls file to a database using SQL Server. I will use temporary tables to copy from the file and then I'll transfer from the temporary tables to the database. Could you please give me an example of such a procedure?

>
EXPERT RESPONSE
There are many ways to import data into SQL Server and what you choose depends greatly on your specific scenario. If you want to simply load contents of a text file into a temporary table, the BULK INSERT command should do the trick. If the number and the order of the columns in the file is the same as in the destination table, your statement could be as simple as this:

BULK INSERT MyTable
FROM 'c:datamydata.txt'
WITH
(
FIELDTERMINATOR =' |',
ROWTERMINATOR =' |\n'
)

If you want to exclude some columns or modify the order of columns, create a format file and specify it as a parameter to BULK INSERT. You can refer to Books Online to learn more about how to use BULK INSERT and how to create a format file.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
SQL Server stored procedures
Check SQL Server database and log file size with this stored procedure
SQL Server source code analysis and management adds database security
SQL and SQL Server Tutorial and Reference Guide
Configure SQL Server Service Broker for sending stored procedure data
Find size of SQL Server tables and other objects with stored procedure
Track changes to SQL Server 2000 and 2005 with one simple utility
Troubleshoot SQL Server 2005 temporary table performance problems
Use SQL Profiler to find long running stored procedures and commands
Stored procedure to monitor long-running jobs in SQL Server 2000
Using BULK INSERT to insert rows from SQL Server dataset to table

Roman Rehak - SQL Server Development and Reporting Services
Using BULK INSERT to insert rows from SQL Server dataset to table
SQL Server query to import database names
Troubleshoot SQL Server 2005 SP2 installation error
Workaround to Reporting Services error in SQL Server Express
How can I export stored procedures in SQL Server 2005?
Code to restore SQL Server databases in VB.NET
Stored procedure for a BULK INSERT to SQL Server 2005 text file
INSTEAD OF trigger to update a SQL Server table
Retrieve images from SQL Server and store in VB.Net
Can you import Excel data to SQL Server Reporting Services?

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
library  (SearchSQLServer.com)
trigger  (SearchSQLServer.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2005 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts