|Encapsulate as Stored Procedure|
The Encapsulate as Stored Procedure command converts the selected code into a new stored procedure and optionally replace it with a call to the new procedure.
This topic contains the following sections:
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->Refactor menu, click Encapsulate as Stored Procedure .
3. The Encapsulate as Stored Procedure dialog box is displayed.
4. Type the name of the owner in the Owner edit box.
5. Type the name of the procedure in the Name edit box.
The procedure name is not checked for duplicate names. If a stored procedure with this owner and name already exists, the script will fail.
6. Review the generated script in the Preview box and modify it if necessary.
7. Select Modify source script to reference the new object if you want SQL Enlight to 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.
8. Click Apply button to apply the changes.
The parameters of the new objects are determined from the variables which are referenced in the selected code.
SQL Enlight automatically 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_variant data type.