How to work with views in dbForge Studio for SQL Server
Last modified: October 1, 2024
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 Studio 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
Create a view
-
In Database Explorer, right-click the Views node and select New View.
- Input name of the view and type a query that will represent the view.
- Save the document by clicking the Update Database button on 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’s SQL statement, every time a user queries a view.
Create a view with the help of snippets
Edit a view
Edit a view by selecting Edit View from the Database Explorer node shortcut menu. In the opened document, you can alter the query text. Once a view is created, you can not modify its name or owner. Save the document to apply changes you’ve made to the query text.
Drop a view
Drop a view by selecting Delete from the Database Explorer node shortcut menu.
Retrieve and modify view data
To retrieve view data, right-click a view in Database Explorer, and then click Retrieve Data on the shortcut menu. The data is rendered in grid-based editor. You can browse and edit view data in the same way as you browse and edit table data.
Note
Some views can be non-updatable. You can not edit their data.
Download dbForge Studio for SQL Server and try it absolutely free for 30 days!
Want to find out more?
Overview
Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All features
Get acquainted with the rich features and capabilities of the tool in less than 5 minutes.
Request a demo
If you consider employing this tool for your business, request a demo to see it in action.