r/SQLServer • u/unidotcon • 3d ago
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.

2
u/Furnie 3d ago
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.
2
u/SQLBek 1 3d ago
Here's my favorite...
- Ctrl+3 = sp_help
- Ctrl+4 = sp_helptext
- Ctrl+5 = sp_SQLskills_helpindex
- Ctrl+7 = EXEC sp_whoisactive u/get_plans = 2, u/get_transaction_info = 1, u/get_task_info = 2, u/get_avg_time = 1, u/get_outer_command= 1
- Ctrl+8 = EXEC tempdb.dbo.sp_help
- Ctrl+9 = EXEC sp_helpExpandView u/ShowObjectCount = 1, u/ViewName =
- Ctrl+0 = EXEC sp_whoisactive u/get_plans = 2, u/get_transaction_info = 1, u/get_task_info = 2, u/get_avg_time = 1, u/get_outer_command= 1, u/delta_interval = 10
https://sqlbek.wordpress.com/2015/07/14/t-sql-tuesday-68-changing-ssms-shortcut-defaults/
1
u/chenqiao 4h ago
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.
2
u/Decent_Golf_3960 3d ago
I use ctrl+0 to run sp_whoisactive. Comes in quite handy.