How to Import a SQL Server Table Inside Excel Sheet? – Interview Question of the Week #273

Question: How do you import a SQL Server table into an Excel worksheet? Use Excel’s SQL Server data connector, select the table or view, and load the result as a table.

Tiles from an organized cabinet are copied into a matching grid in a tray

The pictures in my original example made this straightforward. They show WideWorldImporters and its Sales.InvoiceLines table through Excel’s older Data Connection Wizard. I’ll keep that route here and distinguish it from the Power Query route in current Windows Excel.

Current Windows Excel with Power Query

  1. Choose Data, Get Data, From Database, From SQL Server Database.
  2. Enter the server and optionally the database. Use an authorized Windows or database account with permission to read the intended table.
  3. In Navigator, select the table or view and inspect the preview.
  4. Choose Load to import it, or Transform Data to select columns and filter rows before loading.

You don’t need to write SQL to import a table. For a large source, bring only the data you need. A worksheet has a row limit, so a Data Model or an appropriately filtered query may be more suitable than loading every row into cells.

The original Data Connection Wizard

These retained pictures show the legacy workflow. Menu availability depends on Excel version and whether legacy import wizards are enabled.

1. Open the Data tab, then Get External Data, From Other Sources, From SQL Server.

Original Excel Data ribbon opens the legacy From SQL Server command

2. Enter the server and choose the permitted authentication method. The original connection uses Windows Authentication.

Original SQL Server Data Connection Wizard with Windows Authentication selected

3. Select the database and table. The example selects WideWorldImporters, Sales.InvoiceLines.

Original wizard selects Sales.InvoiceLines in WideWorldImporters

4. Give the connection a useful name, then select Finish. Don’t store a database password in a shared connection file.

Original wizard names a data connection with Save password in file unchecked

5. Choose Table and the destination cell, then OK.

Original Import Data dialog loads a table to an existing worksheet
Original imported table shows InvoiceLineID, InvoiceID and StockItemID columns
Three complete identifier columns from the original imported table. Other table columns are outside this native crop.

Refresh is a read operation

The connection can retrieve new source data when refreshed. Editing imported worksheet cells does not update SQL Server. Review who can open the workbook, its connection and cached data before sharing it.

Related questions cover a full transaction log, TempDB contents and performance facets.

Send an interesting interview question through Twitter or LinkedIn. For help with SQL Server performance, see my health-check service.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

Excel
Previous Post
How to Solve Error When Transaction Log Gets Full? – Interview Question of the Week #272
Next Post
What is Transactional Replication Supported Version Matrix? – Interview Question of the Week #274

Related Posts

1 Comment. Leave new

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.