Article ID: 321686 - Last Review: December 14, 2005 - Revision: 3.3 How to import data from Excel to SQL ServerThis article was previously published under Q321686 On This PageSUMMARY
This step-by-step article demonstrates how to import data from Microsoft Excel worksheets into Microsoft SQL Server databases by using a variety of methods. Description of the TechniqueThe samples in this article import Excel data by using:
RequirementsThe following list outlines the recommended hardware, software, network infrastructure, and service packs that are required:
SamplesImport vs. AppendThe sample SQL statements that are used in this article demonstrate Create Table queries that import Excel data into a new SQL Server table by using the SELECT...INTO...FROM syntax. You can convert these statements to Append queries by using the INSERT INTO...SELECT...FROM syntax while you continue to reference the source and destination objects as shown in these code samples.Use DTS or SSISYou can use the SQL Server Data Transformation Services (DTS) Import Wizard or the SQL Server Import and Export Wizard to import Excel data into SQL Server tables. When you are stepping through the wizard and selecting the Excel source tables, remember that Excel object names that are appended with a dollar sign ($) represent worksheets (for example, Sheet1$), and that plain object names without the dollar sign represent Excel named ranges.Use a Linked ServerTo simplify queries, you can configure an Excel workbook as a linked server in SQL Server. For additional information, click the article number below to view the article in the Microsoft Knowledge Base:306397
(http://support.microsoft.com/kb/306397/EN-US/
)
HOWTO: Use Excel with SQL Server Linked Servers and Distributed Queries
The following code imports the data from the Customers worksheet on the Excel linked server "EXCELLINK" into a new SQL Server table named XLImport1:
Use Distributed QueriesIf you do not want to configure a persistent connection to the Excel workbook as a linked server, you can import data for a specific purpose by using the OPENDATASOURCE or the OPENROWSET function. The following code samples also import the data from the Excel Customers worksheet into new SQL Server tables:Use ADO and SQLOLEDBWhen you are connected to SQL Server in an ADO application by using Microsoft OLE DB for SQL Server (SQLOLEDB), you can use the same "distributed query" syntax from the Using Distributed Queries section to import Excel data into SQL Server.The following Visual Basic 6.0 code sample requires that you add a project reference to ActiveX Data Objects (ADO). This code sample also demonstrates how to use OPENDATASOURCE and OPENROWSET over an SQLOLEDB connection. Use ADO and the Jet ProviderThe sample in the preceding section uses ADO with the SQLOLEDB Provider to connect to the destination of your Excel-to-SQL import. You can also use the OLE DB Provider for Jet 4.0 to connect to the Excel source.The Jet database engine can reference external databases in SQL statements by using a special syntax that has three different formats:
Troubleshooting
REFERENCESFor additional information about how to use Excel as a data source, click the article number below
to view the article in the Microsoft Knowledge Base:
257819
(http://support.microsoft.com/kb/257819/EN-US/
)
HOWTO: Use ADO with Excel Data from Visual Basic or VBA
For additional information about how to transfer data into Excel, click the article numbers below
to view the articles in the Microsoft Knowledge Base:
295646
(http://support.microsoft.com/kb/295646/EN-US/
)
HOWTO: Transfer Data from ADO Data Source to Excel with ADO
247412
(http://support.microsoft.com/kb/247412/EN-US/
)
INFO: Methods for Transferring Data to Excel from Visual Basic
246335
(http://support.microsoft.com/kb/246335/EN-US/
)
HOWTO: Transfer Data from an ADO Recordset to Excel with Automation
319951
(http://support.microsoft.com/kb/319951/EN-US/
)
HOW TO: Transfer Data to Excel by Using SQL Server Data Transformation Services
306125
(http://support.microsoft.com/kb/306125/EN-US/
)
HOW TO: Import Data from SQL Server into Microsoft Excel
APPLIES TO
| Article Translations
|
Back to the top
