3

I use SQL Server Management Studio. One of the time-saving features that helps me a lot they way you can set new keyboard shortcuts. I've set a combination of keys to execute sp_helptext, so I can select the name of a stored procedure and see its definition on the results pane.

I am trying to use Visual Studio (2013 pro) now to work on my SQL code. I can't find any way to set new key combinations like I do in SSMS.

Is it possible to set a shortcut for sp_helptext in VS? How can I do it?

Arulkumar
  • 12,966
  • 14
  • 47
  • 68
Geeky Guy
  • 9,229
  • 4
  • 42
  • 62
  • https://msdn.microsoft.com/en-us/library/5zwses53%28v=vs.120%29.aspx – sandeep rawat May 23 '16 at 15:19
  • Are you using Database projects to manage your sql code? – Steve Ford May 26 '16 at 14:32
  • In Sql Server Object Explorer highlight the stored procedure and hit Enter – Steve Ford May 26 '16 at 14:47
  • @SteveFord I am not using database projects. I'd like to select the name of a procedure where a piece of C# code is going to use it (via `SqlCommand.ExecuteNonQuery`). – Geeky Guy May 26 '16 at 17:46
  • Do I get it correctly that you'd like some UI element which would list all your stored procedures? And you need the ability to select an item from this UI and insert some text into your code? This sounds to me that you need to extend the intellisense dropdown list. It can be achieved as described here: http://stackoverflow.com/a/10527253/1410281. The only trouble I see is that you are on VS2013, so you can't rely on Roslyn to know when (only if the caret is inside `SqlCommand.ExecuteNonQuery`) you have to show the list. – Tamas May 27 '16 at 14:05
  • @Tamas-SonarSourceTeam in SSMS I can select the name of a procedure, press CTRL+F1 and the whole text of the procedure will show up in the result window. I'd like to do so in Visual Studio. – Geeky Guy May 27 '16 at 14:51

2 Answers2

1

In the end what worked was getting all the stored procedures text in .sql files in Visual Studio. This way, if I have a piece of C# code that looks anything like the example below:

SqlCommand command = new SqlCommand("SAMPLE_PROCEDURE", someConnection); // snip

I can select the name of the stored procedure (in this case, SAMPLE_PROCEDURE), hit CTRL + ,, and then the corresponding .sql file will automatically be opened in a new tab.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Geeky Guy
  • 9,229
  • 4
  • 42
  • 62
1

This Visual Studio Extension is the one you are looking for.

Added some extra commands for Visual Studio SQL editor under the menu "SQL", so you can do the same things as with SQL Server Management Studio. For example, select the table name, then press the shortcut key, it will run "exec sp_help tableName".

  • To run sp_help, press "Alt + 2";
  • To run sp_helpText, press "Alt+ 3";
  • To search for tables by the table name, press "Alt+ 4";
  • To search for tables by the column name, press "Alt+ 5";
  • To search for dependencies, press "Alt+ 6";
  • To search for stored procedures, press "Alt+ 7";
  • To run "Select * from table", press "Alt+ 0";

Crollan's SQL Server Management Studio addIn - Crollan SQL Auto Complete, has lots of other powerful features. One of them is to automatically find out the potential ways to join tables. The addIn can be found on

https://visualstudiogallery.msdn.microsoft.com/bf161b31-0826-4f07-905b-d5d09c1227bb or

Crollan.com

L Y E S - C H I O U K H
  • 4,765
  • 8
  • 40
  • 57
user1111
  • 1,840
  • 2
  • 14
  • 18