Manage procedures

In this topic, you will learn how to create, edit, delete, duplicate, and manage procedures from Database Explorer.

Create a stored procedure

1. In Database Explorer, right-click a procedure or Programmability > Procedures node and select New Procedure.

2. In a SQL document, enter the CREATE PROCEDURE statement. For more information, see Procedure Designer.

3. At the bottom of the SQL document, click Apply Changes.

Edit a stored procedure

You can edit a stored procedure in one of these ways.

Edit using Modify via SQL

1. In Database Explorer, right-click the stored procedure you want to edit and select Modify via SQL.

2. In a SQL document, edit the stored procedure.

3. In the top menu, select File > Save or press Ctrl+S.

Edit using Open Editor

1. In Database Explorer, right-click the stored procedure you want to edit and select Open Editor.

2. In a SQL document, edit the stored procedure.

3. At the bottom of the SQL document, click Apply Changes.

Alternatively, in the top menu, select File > Save or press Ctrl+S.

Delete a stored procedure

1. In Database Explorer, right-click the stored procedure you want to delete and select Delete, or press Delete.

2. Click Yes to confirm the deletion.

Note

You cannot undo the drop stored procedure operation, as this action permanently deletes its structure. It is recommended that you back up the database before deleting it.

Debug a stored procedure

1. In Database Explorer, right-click the stored procedure you want to execute and select Execute.

2. In the Edit parameters dialog, enter the input parameters.

3. Click OK.

Note

If the stored procedure calls a function or a trigger, in Database Explorer, select Step Into from the shortcut menu and follow the steps from How to debug a stored procedure.

Duplicate a stored procedure

1. In Database Explorer, right-click a required stored procedure and select Duplicate Object.

2. In the Duplicate Object dialog, configure the object settings:

  • In Destination connection, select the target server.
  • In Destination database, select the target database.
  • In Destination schema, select the target schema.
  • In New object name, specify the object name.
  • Select Drop destination object to drop the destination object if it already exists.
  • Optional: Select Script Changes, then select To New SQL Window to open the generated script in a new SQL document, or To Clipboard to copy it to the clipboard.

3. Click OK.

Generate a script for a stored procedure

1. In Database Explorer, right-click a required stored procedure and select Generate Script As, then select the statement type.

2. Select the output option:

  • To New SQL Window – Opens the script in a new SQL document.
  • To File – Generates the script to a .sql file.
  • To Clipboard – Copies the script to the clipboard.

For more information, see Generate the DDL and DML statements for database objects.

Manage unit tests

Right-click the stored procedure or Procedures node and select:

  • Unit Test > Add New Test to create a unit test for a specific database.
  • Unit Test > View Test List to view unit tests in the database.
  • (only for the Procedures node): Unit Test > Run All Test to run all tests against the database.

Add a stored procedure to the database diagram

To add a stored procedure to the database diagram, in Database Explorer, right-click a required stored procedure and select Send To > Database Diagram.

View stored procedure properties

To view stored procedure properties, in Database Explorer, right-click the stored procedure or Procedures node and select Show Details.

Object Viewer opens, displaying detailed information about the stored procedure.

Refresh the stored procedure

To update the stored procedure to reflect the latest changes, in Database Explorer, right-click the stored procedure or Procedures node and select Refresh, or press F5.

Open the Properties pane

To open the Properties pane, in Database Explorer, right-click the stored procedure and select Properties, or press F4.

Filter stored procedures

1. In Database Explorer, right-click the Procedures node and select Filter.

2. In the Filter Settings (Procedures) dialog, configure the filter parameters.

3. Click OK to apply the filter.

Note

When you open the Procedures node, the number of objects it contains appears in parentheses next to the node name. This number changes based on your filter settings.