With my recent job, I am facing a problem to type frequently used queries again and again in query analyzer to execute. Searched for the best solution to avoid my typing practice and I found following ways to accomplish my task
- Write down queries that I need frequently and save them separately on my hard drive and to get them back, click on open file and connect it to my required Database Server and EXECUTE.
- Using Project
- Create a new Project by selecting a template SQL SERVER SCRIPTS
- Go to Solution Explorer, right click Queries folder and click on New Query.
- Type your new query and save it.
- Now we can use query by just double click on your required one.
But for short queries and some long scripts too, which are more often used in my current projects. I tried to find out more quick ways and come a cross to Keyboard Shortcuts Keys to execute these most frequently used queries.
Is it possible in Sql Server Management Studio?
Yes, though with limitations, but it is possible to execute your frequently used queries with shortcuts keys.
1. Execute queries by writing them in single line.
2. Max 32767 characters long query is possible
3. Parameters can’t be declared
4. Store Procedures, that doesn't require any parameter value or with default values are possible to execute
How to do?
1. Open Sql Server Management Studio
2. In menu bar click on tools and select options
3. Expend “Environment” and click on Keyboard
We can find that shortcut keys for three commonly used System Stored Procedures are already created.
Lets create shourtcut key for our own query
(for adventureworks )
SELECT * FROM Production.Product