You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just wanted to say this article is great!
It had not crossed my mind to create parametrized query shortcuts via the sp_executesql system procedure.
Even using it for a simple "SELECT TOP (100) *" is handy.
I must've passed this settings window so many times and I missed all these "obvious" tricks.
I've created shortcuts for getting row counts (via system views), index details, and index fragmentation of a table all at the click of a few buttons.
It's almost too fun/easy!
I also found another potentially useful shortcut which would look like the following:
"IF @@ServerName != N'YourDevServer' BEGIN RAISERROR(N'You''re not on the development server, by the way. This batch will abort.', 16, 1); RETURN; END; "
You don't actually pass a parameter into it - you would just use it as an F5 replacement when you want to execute unrelated queries.
It would act as a precursor statement to every batch you send.
Admittedly, remembering to press CTRL + 9, say, over F5 is quite hard to remember, but I thought I'd share my two cents on this, anyway.
Thanks again for this article, and I look forward to reading more.
@Glasses93 haha! Too funny. (regarding the F5 safety) This exact usage just occurred to me last night while responding to reddit posts in r/SQLServer. Someone was talking about how they accidentally ran something in production, so they replaced their F5 key with a red one. And then this exact usage popped into my head.
I even thought about re-mapping F5 and ctrl+E to something else so that you don't hit it out of habit. Having two different execution keys, one for production and one for dev may be a good way to handle it.
Hey There! Great stuff, but I am having an issue with one and I have no idea why?
I have this assigned to Crtl+8:
SELECT FORMAT(COUNT(*),'N0')AS Row_Count FROM [space]
But when I highlight a table name, or a schema and a table name, I get....nothing. I've pasted the actual SQL into a query widow and executed it, which runs fine. So not sure.
Just wrote up this script-let for my new v20 install. Does the backup and has error handling if the QueryShortcutsXmlElement doesn't exist. Thanks again Chad for putting this together.
Activity
Glasses93 commentedon Feb 9, 2021
Hey,
I just wanted to say this article is great!
It had not crossed my mind to create parametrized query shortcuts via the sp_executesql system procedure.
Even using it for a simple "SELECT TOP (100) *" is handy.
I must've passed this settings window so many times and I missed all these "obvious" tricks.
I've created shortcuts for getting row counts (via system views), index details, and index fragmentation of a table all at the click of a few buttons.
It's almost too fun/easy!
I also found another potentially useful shortcut which would look like the following:
"IF @@ServerName != N'YourDevServer' BEGIN RAISERROR(N'You''re not on the development server, by the way. This batch will abort.', 16, 1); RETURN; END; "
You don't actually pass a parameter into it - you would just use it as an F5 replacement when you want to execute unrelated queries.
It would act as a precursor statement to every batch you send.
Admittedly, remembering to press CTRL + 9, say, over F5 is quite hard to remember, but I thought I'd share my two cents on this, anyway.
Thanks again for this article, and I look forward to reading more.
Steve
chadbaldwin commentedon Feb 9, 2021
@Glasses93 haha! Too funny. (regarding the
F5
safety) This exact usage just occurred to me last night while responding to reddit posts in r/SQLServer. Someone was talking about how they accidentally ran something in production, so they replaced their F5 key with a red one. And then this exact usage popped into my head.I even thought about re-mapping
F5
andctrl
+E
to something else so that you don't hit it out of habit. Having two different execution keys, one for production and one for dev may be a good way to handle it.mattcargile commentedon Oct 6, 2021
Great stuff! Love the poor man's snippet deal too!
SQL-Ronin commentedon Apr 18, 2024
Hey There! Great stuff, but I am having an issue with one and I have no idea why?
I have this assigned to Crtl+8:
SELECT FORMAT(COUNT(*),'N0')AS Row_Count FROM [space]
But when I highlight a table name, or a schema and a table name, I get....nothing. I've pasted the actual SQL into a query widow and executed it, which runs fine. So not sure.
Thanks!
Glasses93 commentedon Apr 18, 2024
Have you opened a new query since assigning the shortcut?
SQL-Ronin commentedon Apr 18, 2024
Aaaaaahhhh! That did it!! Didn't even think of that! Thank you!
mattcargile commentedon Nov 15, 2024
Just wrote up this script-let for my new v20 install. Does the backup and has error handling if the
QueryShortcuts
XmlElement
doesn't exist. Thanks again Chad for putting this together.