![]() |
Views |
|
Introduction |
|
When studying data analysis, a query is a technique of isolating a series of columns and/or records of a table. This is usually done for the purpose of data analysis. This can also be done to create a new list of items for any particular reason. Most of the time, a query is created temporarily, such as during data analysis while using a table, a form, or a web page. After using such a temporary list, it is then dismissed. Many database applications, including Microsoft SQL Server, allow you to create a query and be able to save it for later use, or even to use it as if it were its own table. This is the idea behind a view. |
A view is a list of columns or a series of records retrieved from one or more existing tables, or as a combination of one or more views and one or more tables. Based on this, before creating a view, you must first decide where its columns and records would come from. Obviously the easiest view is one whose columns and records come from one table.
To create a view, you can use the Object Explorer (Microsoft SQL Server Management Studio), a query window (Microsoft SQL Server Management Studio), or the Server Explorer (Microsoft Visual Studio). Before starting the view, you would have to specify the table(s) that would be involved. To create a view from the Object Explorer or the Server Explorer, you can expand the database, right-click Views and click New View or Add New View. This would open the Add Table dialog box:
The basic functionality of this dialog box is exactly the same as we reviewed for data analysis in the previous lesson:
The structure of a view can be considered complete when the
SELECT statement is as complete as possible. At any time, to test the results of a view, you can run it.
To do this, in the Microsoft SQL Server Management Studio you can click the Execute SQL button
As reviewed during data analysis and when creating joins in previous lessons, you can add conditions in a view to make it isolate only some records. Here is an example:
In our lessons, here are the rules we will use to name our views:
After saving a view, it becomes part of the Views node of its database: a node would be created for it and its name would appear in the Views node of its database. As stated already, one of the reasons for creating a view is to be able to use it over and over again. To achieve this, the view must be saved. Like most objects in Microsoft SQL Server, a view must have a name and it is saved as its own object. To save a view from the view window, you can click the Save button on the toolbar. You can also attempt to close the window. You would then be prompted to save it. When saving a view, you should give it a name that follows the rules and suggestions of SQL.
As stated already, a view is a technique of selecting records to view or use over an over again. After a view has been created, you can open it. You have two main options.
Executing a view consists of seeing its results. To do this, you have various options. To view the results of a view:
|
|
|
||
| Home | Copyright © 2008-2010 FunctionX, Inc. | Next |
|
|
||