Skip to content

Encapsulate as View

The Encapsulate as Viewcommand converts the selected code into a new view and optionally replaces it with a SELECT from the new view.

⚡ ** note: ** Only single SELECT statements which do not reference variables can be encapsulated as views. SELECT INTO and SELECT @local_variable statements are not allowed.

To encapsulate code as a new view:

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

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

  3. The Encapsulate as Viewdialog box is displayed.

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

refactoring-4

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

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

⚡ ** note: ** The view name is not checked for duplicate names. If a view with this schema 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 function. The generated reference to the new view is a SELECT statement:

SELECT *
FROM [dbo].[NewView]
  1. Click Applybutton to apply the changes.

Refactoring