r/SQLServer • • Oct 14 '26

Discussion Brainstorms on SQL query custom shortcuts in SSMS

What are the most frequently used T-SQL queries to have and what are the best keys to use.
So far I have been using "SELECT * FROM" and "SELECT TOP 1000 * FROM" a custom line called "sp_ts". I wanted to see if you guys have other queries that would save loads of time.

This is what custom shortcuts I am referring to. I don't have any shortcuts yet since I am waiting to gain access.
3 Upvotes

8 comments sorted by

4

u/SQLBek 1 Oct 14 '26

Here's my favorite...

https://sqlbek.wordpress.com/2015/07/14/t-sql-tuesday-68-changing-ssms-shortcut-defaults/

1

u/unidotcon Oct 20 '26

thanks for the link! I was trying to find resources online and I didn't catch this TT

3

u/Furnie Oct 14 '26

I have a few.

Ctrl+6: Select top 100 * from <Log database>.dbo.v_progresslog order by 1 desc

This shows me what's recently run.

Ctrl+7 If DB_NAME() = 'DBName1' use DBName2 Else If DB_NAME() = 'DBName2 ' use DBName3 Else If DB_Name() = 'DBName3' use DBName4 Else IF DB_Name() = 'DBName5 ' use DBName1 Else Use DBName1

This allows me to quickly change my active database by looping through the commonly used databases. Unfortunately I can only run it on one specific instance as If the database names don't exist the query fails to run, even if the logic wouldn't call that bit.

Ctrl+8: it's a bit long to go through psudomonising, but it checks the @@ServerName value and depending on what it returns, does a select that unions a sumary of our data freshness tables for that instance, so at a glance I can see when the most important tables for the instance were last updated.

1

u/unidotcon Oct 20 '26

wait Ctrl + 7 is genius, like I could technically make it run on a query like '1' to look for db_1 and so on? I'm going to try this out thanks for the idea!!

1

u/chenqiao Oct 17 '26

For query shortcuts, I rely heavily on metadata queries. Here are my favorites:

Ctrl+3 -> sp_helptext: Select a proc or view name, hit Ctrl+3, and instantly see the definition.

Ctrl+4 -> sp_help: Select a table name, hit Ctrl+4, and see all columns, data types, and indexes.

Alt+F1: (Default) sp_help. Still undefeated.

Instead of mapping a shortcut to SELECT * FROM, mapping to SELECT TOP (100) * FROM is usually safer for production environments. Also, a huge timesaver is mapping a shortcut to SELECT * FROM sys.dm_db_index_usage_stats when troubleshooting.

1

u/unidotcon Oct 20 '26

this seems really good for industry practices, thanks for your insights!

3

u/Decent_Golf_3960 Oct 14 '26

I use ctrl+0 to run sp_whoisactive. Comes in quite handy.

1

u/navicat-gu 26d ago

Good list in the comments already. A few more that save me time, grouped by what they're for. In SSMS they go under Tools > Options > Environment > Keyboard > Query Shortcuts, and the shortcut runs with the selected text appended:

  1. Look at an object: sp_help (columns, keys), sp_helptext (definition of a view or proc), sp_helpindex.
  2. Find things: a small proc of your own like sp_find that searches sys.objects and sys.sql_modules for a name or string. Select a word, hit the key, and you see every proc that references it.
  3. What's running: sp_WhoIsActive (Adam Machanic) with your favourite parameters, and sp_BlitzWho from the First Responder Kit.
  4. Row counts without scanning: a query on sys.dm_db_partition_stats grouped by table, much faster than COUNT(*) on big tables.
  5. Recent activity: like Furnie's log view, a shortcut that selects the last 100 rows from whatever audit or job-history table you check most often.

Two tips: keep the procs in a shared utility database (or master with the sp_ prefix so they resolve from any database context), and keep the list in source control so it survives a new laptop. For longer templates, SSMS code snippets (Ctrl+K, Ctrl+X) are better than shortcuts.

Disclosure: I'm RC, Director of Digital Strategy @ Navicat. If you also work outside SSMS, Navicat 18 has reusable code snippets for SQL Server that can sync across machines, and that's included in the free Navicat Premium Lite.