This article has been
excerpted from book "A Programmer's Guide to ADO.NET in C#".
A view is a virtual table that represents data from one or more than one
database table. You can select data from a single or multiple tables based on
the sort and filter criteria (using the WHERE and GROUP BY clauses) and save
data as a view. You can also set permissions on views. For example, a manager,
an accountant, and a clerk of a company share the same database. The accountant
can access partial data from multiple tables, and the clerk can access partial
data from a single table. You can create three different views based on these
user rights and let the user's access these views based in their rights.
Creating a View
Similar to stored procedures, you can create and manage views from the server
explorer. To create a view, you can expand a database, right-click on the Views
leaf, and select the New View option. This action launches the wizard, which
lets you pick tables. The Add button adds tables to the view designer (see
Figure 10-17).

Figure 10-17: Adding tables to the view designer
I added three tables to the designer: Customers, Order, and Employees. I
selected only a few columns from each table (see Figure 10-18).

Figure 10-18: Creating a view after selecting columns from three tables
Now you can save a view by using the save buttons or menu or by right – clicking
on the view and selecting the save option (see Figure 10-19).

Figure 10-19: Saving a view
I called the view CustEmpView and clicked OK (see Figure10-20).

Figure 10-20: Click OK to save a view.
Now when you see the Server Explorer views, you'll see CustEmpView listed (see
Figure 10-21).

Figure 10-21: Available views in the Server Explorer
Executing Views from VS .NET




Join the conversation! Your thoughts help the community grow.