How to Copy SQL Result Grids to the Clipboard
A SQL result set is one of the most copied artifacts in daily developer and analyst work. A user runs a query, selects the result grid, presses Ctrl+C, and pastes into Excel, a Markdown file, a Slack message, or an email. The paste either arrives as a clean table or as a row of tab-separated values that Excel interprets correctly but Slack does not. The difference is not the SQL client; it is the clipboard format the client wrote. SQL Server Management Studio, Azure Data Studio, DBeaver, pgAdmin, and MySQL Workbench each ship multiple copy commands, and each command writes a different combination of clipboard formats. Knowing which command writes which format is the difference between a clean paste and a re-do.
This guide covers what each major SQL client puts on the clipboard, which destination prefers which format, and how to verify what actually arrived. For neighbouring topics, see copying hex dumps and keeping alignment, Markdown READMEs: screenshots as files in /docs, and best clipboard habits for developers in 2026. The Windows clipboard history limit of 25 items applies; see Windows clipboard settings, line by line for the underlying limits.
What the clipboard actually carries
Windows clipboard history stores three first-class formats per item: plain text, HTML, and bitmap. A SQL client that copies a result grid typically writes multiple formats in parallel — the OS clipboard is a multi-format container, not a single slot. The most common combinations are:
| Copy command | Plain text | HTML | CSV/TSV intent |
|---|---|---|---|
| Ctrl+C on selected cells | TSV (tab-separated) | Often a <table> | Excel-friendly |
| Copy with headers | TSV with header row | <table> with <th> | Excel-friendly, headers preserved |
| Copy as CSV | CSV (comma-separated) | None | File-save friendly |
| Copy as Markdown | Markdown table syntax | None | Markdown-friendly |
| Copy as JSON | JSON array | None | API-friendly |
When a destination pastes, it asks the clipboard for the most specific format it understands. Excel asks for HTML first, then falls back to text. Slack asks for text and parses tab characters into columns. Markdown editors ask for text. The same clipboard payload therefore pastes differently into different destinations.
The Windows clipboard history panel shows a text preview regardless of what else is on the clipboard. This can mislead: the panel shows TSV text, but Excel still receives the HTML table on paste.
SQL Server Management Studio (SSMS)
SSMS ships three relevant copy commands on the result grid context menu:
- Copy (Ctrl+C) — copies the selected cells as TSV text. No headers. Excel pastes it cleanly into columns; Slack pastes it as tab-separated text that some clients render and some do not.
- Copy with Headers — same TSV format, with the column names as the first row. This is the most useful command for sharing a result set in a ticket.
- Copy as CSV — writes CSV text. Useful when the destination is a file or a tool that expects CSV.
SSMS also has a settings page that controls copy behaviour: Tools → Options → Query Results → SQL Server → Results to Grid. The relevant options are:
- Include column headers when copying or saving results — when checked, Ctrl+C includes headers, equivalent to always using Copy with Headers.
- Quote identifiers containing spaces or special characters — wraps column names that need quoting in CSV output.
- Copy columns as tab-separated values — affects how cells with commas are handled.
A common frustration: a user copies a result set, pastes into Excel, and the columns are merged because Excel received the HTML format, which SSMS did not write. The fix is to verify in SSMS options that the copy is producing the expected output, or to paste into Excel with Paste Special → Text to force the TSV interpretation.
SSMS does not ship a "Copy as Markdown" command. For Markdown output, use Azure Data Studio or a query like SELECT * FROM table FOR JSON PATH and post-process.
Azure Data Studio (ADS)
ADS, the cross-platform successor to SSMS for many workflows, ships a richer copy menu. Right-click a result grid and select:
- Copy — TSV with headers, configurable in settings.
- Copy with Headers — explicit headers.
- Copy as CSV — CSV.
- Copy as JSON — JSON array of objects.
- Copy as Markdown — Markdown table syntax, ready to paste into a
.mdfile or a GitHub comment.
The Copy as Markdown command is the one that saves the most time. A result set copied as Markdown pastes into a GitHub PR comment as a rendered table. The same command in SSMS requires a third-party extension or a manual TSV-to-Markdown conversion.
ADS settings live in File → Preferences → Settings → Query Results. The relevant toggles are copyIncludeHeaders and copyOnSelect. Setting copyIncludeHeaders to true makes Ctrl+C include headers by default.
DBeaver
DBeaver is a cross-platform, Eclipse-based SQL client popular with analysts who work across SQL Server, Postgres, MySQL, and SQLite. Its copy menu is the most granular of the major clients:
- Copy — TSV, with headers configurable in preferences.
- Advanced Copy — opens a dialog with format choices: CSV, TSV, HTML, JSON, XML, Markdown, SQL INSERT statements.
- Copy as SQL INSERT — produces
INSERT INTO ... VALUES (...)statements, useful for seeding a test database.
The Advanced Copy dialog is the key feature. It lets the user pick the format per copy, set a delimiter, choose whether to include headers, and choose whether to quote string values. For a result set that will be pasted into a Markdown issue, choose Markdown. For a result set that will be saved as a fixture file, choose SQL INSERT.
DBeaver also supports "Copy Special" with a saved profile, so a frequently used format (for example, "Markdown with headers, no row count") can be applied with one shortcut.
pgAdmin and MySQL Workbench
pgAdmin 4 ships a copy command that writes TSV with headers. There is no native Markdown or JSON copy. For JSON output, use SELECT row_to_json(t) FROM (SELECT ...) t and copy the result column.
MySQL Workbench writes TSV on Ctrl+C, with headers controlled by Edit → Preferences → SQL Editor → Copy Support. The options are "Copy Column Names" and "Quote Values". For Markdown output, use a query like SELECT JSON_ARRAYAGG(JSON_OBJECT(...)) and copy the resulting JSON.
Postgres psql and MySQL mysql CLIs
Command-line clients write to stdout, not to the clipboard directly. The standard pattern is to pipe through clip on Windows:
psql -c "SELECT id, name FROM users LIMIT 10" -U postgres | clip
The output of psql is an aligned table by default, which is good for terminal reading but bad for pasting into Excel. Switch to unaligned, tab-separated output for clipboard-friendly results:
psql -A -F"\t" -c "SELECT id, name FROM users LIMIT 10" | clip
The -A flag is unaligned, -F sets the field separator. The same pattern works for mysql with --batch --skip-column-names:
mysql -e "SELECT id, name FROM users LIMIT 10" --batch --skip-column-names | clip
Pasting into Excel
Excel prefers HTML over plain text when both are on the clipboard. This is usually the right behaviour — an HTML table preserves column types and formatting — but it can produce surprises when the SQL client's HTML is sparse.
When the paste is wrong, use Paste Special → Text to force the TSV interpretation. This drops any HTML and lets Excel parse the tabs itself. The result is a clean table with the columns in the right order.
A common pitfall: a result set with a column that contains commas (for example, a free-text address field) will break in CSV format but survive in TSV format. If the destination is Excel, prefer TSV. If the destination is a file that another tool will read, prefer CSV with proper quoting.
Pasting into Markdown
A TSV result set pastes into a Markdown file as tab-separated text, which renders as a single paragraph — useless. The right approach is to use a SQL client that writes Markdown directly (ADS or DBeaver), or to convert TSV to Markdown with a tool.
The simplest conversion is to do it by hand for small tables. For larger tables, a PowerShell one-liner works:
$input | ForEach-Object { $cols = $_ -split "`t"; "| " + ($cols -join " | ") + " |" }
Run after copying the TSV to the clipboard and pasting into the PowerShell session as input. The output is a Markdown table body. Add the header row and separator by hand.
For a deeper comparison of snippet and table storage strategies, see snippet managers for code: project files win and how to copy a table from a webpage intact, which covers the same multi-format problem from the browser side.
Pasting into Slack and Teams
Slack and Teams both render monospace blocks inside triple backticks. A TSV result set inside backticks becomes a fixed-width table, which is readable if the columns are narrow. For wide result sets, the table wraps and becomes unreadable.
The pattern that works:
- For narrow result sets (3-4 columns, short values), paste TSV inside triple backticks.
- For wide result sets, save the result as a CSV file and attach it.
- For result sets that need to be shared in a ticket rather than chat, paste as a Markdown table in the ticket description.
Slack has a /table shortcut in some workspaces that converts TSV to a formatted table, but it is not available by default and depends on workspace apps.
Verifying what is on the clipboard
When a paste behaves unexpectedly, the first step is to inspect what the SQL client actually placed on the clipboard. The most reliable check is a PowerShell snippet using the .NET clipboard API:
Add-Type -AssemblyName System.Windows.Forms
$cb = [System.Windows.Forms.Clipboard]
$cb.ContainsText(); $cb.ContainsHtml(); $cb.ContainsFileDropList()
This prints True or False for each format. If ContainsHtml() is True, Excel will receive HTML on paste; if False, Excel falls back to text.
For more on clipboard inspection, see how to see what is currently on your clipboard and how Windows treats rich text versus plain text.
A copy-decision table
| Destination | Recommended client | Recommended copy format |
|---|---|---|
| Excel | SSMS, ADS, DBeaver | Copy with Headers (TSV) or HTML |
| GitHub PR comment | ADS, DBeaver | Copy as Markdown |
| Slack chat | Any | TSV inside triple backticks, or attach CSV |
| Any | HTML table (paste as rich text) | |
| Test fixture file | DBeaver | Copy as SQL INSERT |
| API documentation | ADS, psql | Copy as JSON |
A short checklist
- Know which copy command writes which format. SSMS, ADS, and DBeaver each name them differently.
- For Excel destinations, TSV with headers is the most reliable format. Use
Paste Special → Textif the wrong format wins. - For Markdown destinations, use a client that ships
Copy as Markdown. ADS and DBeaver do; SSMS does not. - For chat, prefer attaching a CSV over pasting a wide table inline.
- Verify with the .NET clipboard API when a paste behaves oddly.
Related reading
- Markdown READMEs: Screenshots as Files in /docs
- Code Review Comments: Stage Before You Submit
- Best Clipboard Habits for Developers in 2026
- Clipboard Tools on Multi-Monitor Windows Setups
Sources
- Microsoft Learn — SQL Server Management Studio keyboard shortcuts — official SSMS documentation listing copy commands and their shortcuts, including Copy with Headers
- Azure Data Studio — Query Results documentation — official ADS documentation covering result grid copy options including Copy as Markdown and Copy as JSON
- DBeaver — Data transfer and copy documentation — DBeaver's official documentation for the Advanced Copy dialog and supported export formats
- Microsoft Learn — Clipboard formats (Win32) — official reference for CF_TEXT, CF_UNICODETEXT, CF_HTML, and CF_HDROP, which govern how a SQL result set is carried across apps
- PostgreSQL documentation — psql command-line options — official psql manual covering
-A(unaligned) and-F(field separator) flags used for clipboard-friendly output
Deepender Yadav is a B.Tech Computer Science Engineering student and software developer interested in building practical software and open-source projects.
GitHub · LinkedInCopy. 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