How to: Run Stored Procedures and User-Defined Functions

You can run stored procedures and user-defined functions against your database and display the results in the Output window. Stored procedures and user-defined functions must be saved before you can run them. If you attempt to run an unsaved SQL routine, a message prompts you to save it first.

NoteNote

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Customizing Development Settings in Visual Studio.

To run a stored procedure

  1. In Server Explorer, expand the Stored Procedures folder.

  2. Right-click the name of the stored procedure that you want to run.

  3. Choose Execute on the shortcut menu. The Output window shows the status of the stored procedure.

  4. If the stored procedure contains parameters, the Run Stored Procedure dialog box prompts you for the parameter values. In the Value column, type a value for each parameter that appears in the Name column, and then click OK. For details about parameters, see How to: Use Parameters in Stored Procedures and User-Defined Functions.

    The Output window is updated with status information as the stored procedure is run. The Output window also displays result sets and return values for the stored procedure.

To run a user-defined function

  1. In Server Explorer, expand the Functions folder.

  2. Right-click the name of the function that you want to run and click Execute on the shortcut menu. The Output window shows the status of the function.

  3. If the function contains parameters, the Run Stored Procedure dialog box prompts you for the parameter values In the Value column, type a value for each parameter that appears in the Name column, and then click OK. For details about parameters, see How to: Use Parameters in Stored Procedures and User-Defined Functions.

Community Additions

Show: