5.6 SQL Editor

If you edit a stored procedure, a function, or any SQL script file, Visual Studio .NET will show the SQL editor. This is just the normal Visual Studio .NET text editor window, but in a SQL mode. It supports syntax coloring for various dialects of SQL. (PL/SQL, T-SQL, T-SQL7, and T-SQL8 are all supported.) It also allows stored procedures to be executed and debugged. Unfortunately, IntelliSense is not supported in SQL mode.

If you double-click on a stored procedure or function, the SQL editor window will appear with an ALTER PROCEDURE or ALTER FUNCTION statement containing the SQL source code. (This is to make it easy to modify functions. Note that this use of ALTER is peculiar to SQL Serversome databases use the REPLACE keyword instead.) The editor will also allow you to set breakpoints. You can then execute the statement with Database Run Stored Procedure (Ctrl-E), and the procedure will run until it hits the breakpoint, at which point you can single-step through the code. You can also start single-stepping straightaway with Database Step Into Stored Procedure (Alt-F5).

Debugging of stored procedures is supported only for SQL Server. There are also some installation prerequisitessee Chapter 3 for more information on setting up SQL Server debugging.

You can use the query and view designer to add a SQL statement into a SQL editor window. Simply select Insert SQL from the SQL editor's context menu and the query designer will appear. When you save the query, it will insert the generated SQL into the editor. (If you are using this to edit a stored procedure, saving the query will modify only the contents of the SQL editor window. It will not save it back into the database until you save the stored procedure itself.) You can also use the query and view designer to edit existing SELECT, UPDATE, INSERT, and DELETE statementsif you bring up the context menu in the editor on a statement and select Design SQL Block, the query and view designer will be opened, and the diagram and grid will be generated from the SQL.