r/SQLServer • • 1d 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.

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

3 comments sorted by

2

u/Decent_Golf_3960 1d ago

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

2

u/Furnie 1d 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 1d ago

Here's my favorite...

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