Working with Views
Last modified: October 23, 2019
A view is a virtual table based on the result-set of an SQL statement. A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database.
dbForge Fusion for SQL Server allows you to create, modify, and drop views, retrieve and alter data in underlying tables.
Prerequisites
In order to start creating a view, you should have the following privileges:
- CREATE VIEW on the proper database
- SELECT privilege on the proper tables
Creating a View
-
In Database Explorer, right-click the Views node and select New View.
-
Input a name of the view and type a query that will represent the view.
-
Save the document by clicking the Update Database button at the bottom of the window, or the Save button on the Standard toolbar. If there are any errors in the SQL syntax, you will be notified about it.
CREATE VIEW Syntax
CREATE VIEW HumanResources.vEmployeeDepartment
AS
SELECT
e.[BusinessEntityID]
,p.[Title]
,p.[FirstName]
,p.[MiddleName]
,p.[LastName]
,p.[Suffix]
,e.[JobTitle]
,d.[Name] AS [Department]
,d.[GroupName]
,edh.[StartDate]
FROM [HumanResources].[Employee] e
INNER JOIN [Person].[Person] p
ON p.[BusinessEntityID] = e.[BusinessEntityID]
INNER JOIN [HumanResources].[EmployeeDepartmentHistory] edh
ON e.[BusinessEntityID] = edh.[BusinessEntityID]
INNER JOIN [HumanResources].[Department] d
ON edh.[DepartmentID] = d.[DepartmentID]
WHERE edh.EndDate IS NULL
Note
A view always shows up-to-date data! The database engine recreates the data, using the view SQL statement every time a user requests a view.
Creating a View Using a Snippet
To simplify the process of a View creation, you may use the CreateView snippet.
-
Click the New SQL button on the Devart - Main toolbar.
-
Right-click anywhere in the SQL document, and then click Insert Snippet. The snippets list will appear.
-
Double-click the CreateView snippet.
-
The following code will be inserted into the document.
5.Edit the code accordingly and save the view.
Editing a View
Edit a view by selecting Edit View from Database Explorer on the shortcut menu. In the document that opens, you can alter the query text. Once a view is created, you cannot modify its name or owner. Save the document to apply changes you’ve made to the query text.
Dropping a View
Drop a view by selecting Delete from Database Explorer on the shortcut menu.
Retrieving and Modifying View Data
To retrieve view data, right-click a view in Database Explorer and select Retrieve Data on the shortcut menu. The data is rendered in a grid-based editor. You can browse and edit the view data in the same way as you browse and edit the table data.
Note
Some views can be non-updatable. You can not edit their data.