Share via


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.

Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

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.

See Also

Other Resources

Working with Stored Procedures and User-Defined Functions