I have a custom Keyboard Query Shortcut in SSMS (2008) with the following t-sql…
SELECT TOP(50) * FROM
This allows me to simply type in a name of a table and press my keyboard shortcut to get the top fifty items from that table. The problem I have is that I like to query using WITH(NOLOCK) so the records don’t get locked. I haven’t figured out how to enter T-SQL into the Keyboard Query shortcut where the input is in the middle of the statement. How can I incorporate a NoLock without resorting to using a stored procedure?
It can get a bit messy, but you can use
sp_executesqlto avoid relying on a stored procedure being defined: