← Back to Blog

Developers & Code | Published Aug 21, 2026 | Updated Oct 13, 2026 | 7 min read

How to Copy SQL Query Results to the Clipboard

By Deepender Yadav

How to Copy SQL Query Results to the Clipboard — Edge Drop Guide

Select the cells in the result grid and press Ctrl+C to copy them as tab-separated text, which Excel splits into columns on paste. Plain Ctrl+C usually leaves out the column names, so use the client's "copy with headers" command instead: Ctrl+Shift+C or right-click > Copy with Headers in SQL Server Management Studio (SSMS), Copy with Headers in the VS Code MSSQL extension, and Copy with headers in pgAdmin. In DBeaver, Ctrl+Shift+C opens Advanced Copy, where you can turn headers on, and its Copy as commands produce Markdown, JSON and other formats.

Copy commands in each SQL client

ClientCopy without headersCopy with headersOther formats
SSMSCtrl+CCtrl+Shift+C, or right-click > Copy with HeadersSave Results As (CSV, text; newer versions add Excel, JSON, Markdown, XML)
VS Code + MSSQL extensionRight-click > CopyRight-click > Copy with HeadersSave results as JSON, Excel or CSV
DBeaverCtrl+CCtrl+Shift+C (Advanced Copy) with "Copy header" onCopy as CSV, HTML, JSON, Markdown, SQL, TXT, XML and more
pgAdmin 4Copy (Ctrl+C) in the Query ToolCopy drop-down > Copy with headersSave results to file (F8), delimited text
psql (command line)-t removes headersDefault output includes headers--csv, -P format=html

Azure Data Studio was retired on February 28, 2026 and no longer gets updates or security fixes. Microsoft's replacement for day-to-day query work is Visual Studio Code with the MSSQL extension, which has the same Copy / Copy with Headers commands in its results grid.

SQL Server Management Studio

To copy a result set with column names:

  1. Click the grid, then select the cells you want, or right-click and choose Select All.
  2. Press Ctrl+Shift+C, or right-click and choose Copy with Headers.
  3. Paste into Excel, a ticket or an email.

If you always want headers, turn them on for plain Ctrl+C too:

  1. Go to Tools > Options > Query Results > SQL Server > Results to Grid.
  2. Check Include column headers when copying or saving the results.
  3. Open a new query window. The option applies to new windows; for the current one, use Query > Query Options > Results > Grid.

Two more things trip people up in SSMS:

  • Multi-line values. A cell that contains line breaks can split one row into several when it lands in Excel. On the same Results to Grid page, Retain CR/LF on copy or save controls whether those line breaks are kept. With it off, the value stays on one line.
  • Large or reusable results. For anything bigger than a screenful, right-click the grid and choose Save Results As. Recent SSMS 22 releases added Excel, JSON, Markdown and XML as file formats there, so you can save a Markdown table directly instead of converting a copy.

VS Code with the MSSQL extension

Run the query, then right-click inside the results grid. The menu offers Select All, Copy, Copy with Headers and Copy Headers. To get a file rather than a clipboard copy, use the save buttons in the results pane, which write JSON, Excel or CSV.

DBeaver

DBeaver's plain Ctrl+C copies the selected values. For anything else, press Ctrl+Shift+C to open Advanced Copy. Its settings include:

  • Copy header to include column names,
  • Copy row numbers,
  • Quote cell values and Always quote values,
  • Column Delimiter, Row Delimiter and Quote Character,
  • Copy as HTML, which puts an HTML table on the clipboard.

The "Copy as" commands go further: CSV, DbUnit, HTML, JSON, Markdown, SQL, Source code, TXT and XML. Copy as Markdown gives you a table you can paste straight into a GitHub issue or a README, and Copy as SQL produces INSERT statements for seeding a test database.

pgAdmin 4

In the Query Tool, highlight rows in the Data Output panel and press Ctrl+C, or use the Copy button. The drop-down next to it has Copy with headers. For a full result set, Save results to file (F8) writes it to a delimited text file such as CSV.

psql and mysql: send output straight to the clipboard

Command-line clients print to the terminal, so pipe the output into the clipboard. In PowerShell, Set-Clipboard takes piped text; in Command Prompt, use clip.

psql's default output is an aligned, padded table that reads well in a terminal but pastes badly into Excel. Ask for CSV instead (PostgreSQL 12 and later):

psql -d mydb --csv -c "SELECT id, name, city FROM customers LIMIT 20" | Set-Clipboard

--csv includes a header row and quotes any value that contains a comma. Add -t to drop the header. For the MySQL client, --batch prints tab-separated rows with a header row (add --skip-column-names to remove it):

mysql --batch -e "SELECT id, name, city FROM customers LIMIT 20" mydb | Set-Clipboard

The PowerShell clipboard cheat sheet covers Get-Clipboard and Set-Clipboard in more detail.

Pasting into Excel without surprises

Tab-separated text pastes into Excel as columns automatically. The problems come from Excel's type guessing, not from the copy:

  • Leading zeros vanish. Zip codes and account numbers such as 00742 become 742. Format the destination columns as Text before you paste.
  • Long IDs turn into scientific notation. Same fix: format the column as Text first.
  • Dates flip day and month. Excel interprets dates using your regional settings. Return dates from the query in ISO format (YYYY-MM-DD) to avoid ambiguity.
  • One row splits into several. A value with embedded line breaks does this. In SSMS, make sure Retain CR/LF on copy or save is off, or replace line breaks in the query.

For a long or wide result, a saved CSV or Excel file is more reliable than the clipboard. If a pasted table brings unwanted fonts or colours into Word or email, how to paste without formatting on Windows shows the plain-text options.

Turning a copied grid into a Markdown table

Tab-separated text pasted into a Markdown file doesn't render as a table. If your client can't copy or save Markdown directly (DBeaver and SSMS 22 can), this PowerShell snippet converts whatever tab-separated rows are on the clipboard into a Markdown table and puts the result back on the clipboard. Copy the grid with headers first, then run:

$rows = @(Get-Clipboard | Where-Object { $_ -ne '' })
$lines = @(foreach ($r in $rows) {
    $cells = $r -split "`t" | ForEach-Object { $_ -replace '\|', '\|' }
    '| ' + ($cells -join ' | ') + ' |'
})
$sep = '|' + (' --- |' * ($rows[0] -split "`t").Count)
@($lines[0], $sep) + @($lines | Select-Object -Skip 1) | Set-Clipboard

The first copied row becomes the header, and any | characters inside values are escaped so they don't break the table. Which apps understand Markdown from the clipboard lists where the result will render.

Sharing results in Slack or Teams

Chat apps don't render tab-separated text as a table, and they reflow long lines. For a few narrow columns, paste psql's aligned output inside a code block (three backticks) so the monospace font keeps the columns lined up. For anything wider, attach a CSV file instead. How to keep line breaks when pasting into Slack covers the formatting side.

Keeping several result sets at hand

Windows clipboard history (Win+V) can hold several copied result sets, so you can copy three queries and paste them into a report one after another. Each item can be up to 4 MB, so very large result sets are better saved as CSV.

If you regularly move query results, CSV fragments and chart screenshots between apps, Edge Drop keeps copied spreadsheet-style text as a card and pastes it back as a table when you click it. How to handle CSV, SQL and chart images on the clipboard shows that workflow.

FAQ

Why does SSMS copy without column names?

Plain Ctrl+C copies only the selected values unless Include column headers when copying or saving the results is checked. Use Ctrl+Shift+C (Copy with Headers) for a one-off copy.

What replaced Azure Data Studio for copying query results?

Microsoft recommends Visual Studio Code with the MSSQL extension. Its results grid has Copy, Copy with Headers and Copy Headers, and it can save results as JSON, Excel or CSV.

How do I copy query results as INSERT statements?

DBeaver's Copy as SQL generates INSERT statements from the selected rows. SSMS has no copy command for this; its Generate Scripts wizard can script table data instead.

Related reading

Sources

Deepender Yadav
Written by Deepender Yadav · Creator & Developer

Deepender Yadav created Edge Drop and builds and tests it, from the edge-hover shelf to each release. A B.Tech Computer Science Engineering student, Deepender writes the Edge Drop guides, comparisons and developer posts, and checks product details against the app's source code.

GitHub · LinkedIn

Copy. Stack. Drop.

Transform your clipboard into an interactive edge shelf. Stack, pin, and drag assets into any app with zero friction.

Download for Windows Get from Microsoft Store

How to Install Guide · First 10 Minutes Guide · Drag & Drop Guide · Edge Drop vs Win+V · Support

Free · Lightweight · Privacy First
Find us on CodeHype