Views

A view is a virtual table based on the result set of a SQL query. It doesn’t store data; the data is dynamically retrieved from underlying tables.

Database Explorer allows you to perform operations on views using the shortcut menu. Right-click a view in Database Explorer to access options for specific tasks, such as creating or editing a view, or exporting or importing data.

Create a view

1. In Database Explorer, right-click a view or the Views node and select New View.

2. In View Editor, specify the view details:

  • Under Query Text, enter the view name, select the schema it belongs to, enter the query, and select view options.
  • Optional: Under Query Design, build the view query on the diagram.
  • Optional: Under Indexes, add indexes for the view.
  • Optional: Under Statistics, set up statistics.
  • Optional: Under Triggers, add triggers.
  • Optional: Under T-SQL, preview the generated script.

3. At the bottom of View Editor, click Apply Changes to save the view.

Edit a view using View Editor

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

2. In View Editor, update the view details.

Note

View Editor doesn’t support changing the view schema. This action requires moving the view to a different schema, rather than modifying its structure.

3. At the bottom of View Editor, select Apply Changes to apply the changes.

Edit a view using SQL

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

2. In a SQL document, edit the view.

3. On the SQL toolbar, click Save to save the changes.

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

Delete a view

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

2. Click Yes to confirm the deletion.

Note

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

Duplicate a view

1. In Database Explorer, right-click a required view 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.

Manage data

1. In Database Explorer, right-click the view and select Open Data in Editor.

Alternatively, select Open Editor and switch to the Data tab.

2. On the Data tab of View Editor, view the data in the grid.

3. To perform any action on the data, right-click the selected row and select the required command from the shortcut menu.

For more information, see Work with data in Data Editor.

Retrieve data

To retrieve data from the selected view, in Database Explorer, right-click it and select Select All Rows.

Rename a view

1. In Database Explorer, right-click the selected view and select Rename.

2. Specify the new view name, then press Enter.

Shortcut menu options for a specific view

The following table describes the shortcut menu options, which appear when you right-click a specific view in Database Explorer.

Name Description
New View Opens View Editor to create and manage a view.
Modify via SQL Opens a SQL document to edit a view using SQL.
Open Editor Opens View Editor to edit a view.
Open Data in Editor Opens the Data tab of View Editor to view and manage view data.
Select All Rows Retrieves data from the selected view.
Manage Index Fragmentation Opens the Index Manager document to analyze SQL indexes by collecting index fragmentation statistics and detecting databases that require maintenance.
Source Control > Source Control Manager Opens Source Control Manager, where you can track and manage changes to database schema and static data.
When Source Control Manager is already open, this option refreshes it.
Source Control > Commit Opens Source Control Manager with all local changes (if any) selected and ready to commit.
When Source Control Manager is already open, this option refreshes it and selects all local database changes.
Source Control > Get Latest Opens Source Control Manager with all remote changes (if any) selected, ready to pull using Get Latest.
When Source Control Manager is already open, this option refreshes it and selects all remote database changes.
Export Data Opens the Data Export wizard to export data to a file with the supported file extension.
Duplicate Object Opens the Duplicate Object dialog to copy object structure and/or data.
Generate Script As Generates a script of the selected view using the CREATE, CREATE OR ALTER, DROP, DROP and CREATE, ALTER, SELECT, INSERT, UPDATE, DELETE, INSERT/UPDATE STORED PROCEDURE, or EXEC sp_refreshview statements. The view can be saved to a new SQL document or a file, or copied to the clipboard.
Send to > Query Builder Adds the selected view to the Query Builder diagram.
Send to > Master Detail Browser Adds the selected view to the Master Detail Browser document.
Send to > Database Diagram Adds the selected view to a database diagram.
Send to > Data Report Adds the selected view to a simple data report.
Send to > Chart Designer Opens Chart Designer to create a chart.
Send to > Pivot Table Opens the query document to create a pivot table.
Show Details Opens Object Viewer to view object details.
Rename Lets you enter a new name for the selected view.
Shortcut: F2
Delete Drops the selected view from the database.
Shortcut: Delete
Refresh Updates the object to reflect the latest changes.
Shortcut: F5
Properties Opens the Properties pane to view the object information.
Shortcut: F4

Shortcut menu options for the Views node

The following table describes the shortcut menu options, which appear when you right-click the Views node in Database Explorer.

Name Description
New View Opens View Editor to create and manage a view.
Source Control > Source Control Manager Opens Source Control Manager, where you can track and manage changes to database schema and static data.
When Source Control Manager is already open, this option refreshes it.
Source Control > Commit Opens Source Control Manager with all local changes (if any) selected and ready to commit.
When Source Control Manager is already open, this option refreshes it and selects all local database changes.
Source Control > Get Latest Opens Source Control Manager with all remote changes (if any) selected, ready to pull using Get Latest.
When Source Control Manager is already open, this option refreshes it and selects all remote database changes.
Tasks > Export Data Opens the Data Export wizard to export data to a file with the supported file extension.
Filter Opens the Filter Settings dialog to control which views should appear in Database Explorer.
Show Details Opens Object Viewer to view object details.
Refresh Updates the object to reflect the latest changes.
Shortcut: F5

Note

After opening the Views node, the number of objects it contains appears in parentheses next to the node name. This number changes based on your filter settings.

The Source Control shortcut menu is available only if you linked the corresponding database to a source-control system.

Bulk operations

In Database Explorer, hold down Ctrl and select multiple views. Then right-click the selection and select the required option.

The following table describes the shortcut menu options available for multiple views.

Name Description
Open Editor Opens View Editors for each selected view.
Open Data in Editor Opens the Data tab of View Editors for each selected view.
Select All Rows Retrieves data from the selected views.
Source Control > Source Control Manager Opens Source Control Manager, where you can track and manage changes to database schema and static data.
When Source Control Manager is already open, this option refreshes it.
Source Control > Commit Opens Source Control Manager with all local changes (if any) selected and ready to commit.
When Source Control Manager is already open, this option refreshes it and selects all local database changes.
Source Control > Get Latest Opens Source Control Manager with all remote changes (if any) selected, ready to pull using Get Latest.
When Source Control Manager is already open, this option refreshes it and selects all remote database changes.
Source Control > Link/Unlink Static Data Opes the Source Control Link Static Data dialog that displays the tables whose data you want to link.
Export Data Opens the Data Export wizard to export data from the selected views.
This option is available only for the views located on the same server.
Generate Script As Generates a script of the selected objects using the CREATE, CREATE OR ALTER, DROP, DROP and CREATE, ALTER, SELECT, INSERT, UPDATE, DELETE, INSERT/UPDATE STORED PROCEDURE, and EXEC sp_refreshview statements.
The script can be generated to a new SQL document or a file, or copied to the clipboard.
Send to > Query Builder Adds the selected views to the Query Builder diagram.
Send to > Master Detail Browser Adds the selected views to the Master Detail Browser document.
Send to > Database Diagram Adds the selected views to a database diagram.
Delete Drops the selected views from the database.
Shortcut: Delete

Bulk operations for multiple views