Skip to content

Encapsulate as Stored Procedure

The Encapsulate as Stored Procedurecommand converts the selected code into a new stored procedure and optionally replaces it with a call to the new procedure.

To encapsulate code as a new stored procedure:

  1. Select the script that you want to use for the new stored procedure.

  2. On the SQL Enlight->Refactormenu, click Encapsulate as Stored Procedure.

  3. The Encapsulate as Stored Proceduredialog box is displayed.

refactoring-1

The SQL script for the creation of the stored procedure is displayed in the Previewbox.

  1. Type the name of the owner in the Owner edit box.

  2. Type the name of the procedure in the Name edit box.

⚡ ** note: ** The procedure name is not checked for duplicate names. If a stored procedure with this owner and name already exists, the script will fail.

  1. Review the generated script in the Previewbox and modify it if necessary.

  2. Select Modify source script to reference the new objectif you want SQL Enlightto modify the originating script and replace the encapsulated code with reference to the new procedure. The generated reference to the new stored procedure is an EXECUTE statement with the procedure parameters.

  3. Click Applybutton to apply the changes.

The parameters of the new objects are determined from the variables which are referenced in the selected code.

SQL Enlightautomatically resolves the data type and the direction of these parameters. If a variable is used but declared nowhere in the script, its declaration in the resulting script will have sql_variantdata type.

Refactoring