3 4
Now that you have a basic understanding of what views are, let's look at them more closely. In this section, you'll learn about the types of views, the advantages of using views, and the restrictions SQL Server places on the use of a view.
Several types of views can be created, each of which has its advantages in certain situations. Which type of view you create is entirely dependent on what you want to use the view for. You can create views in any of the following forms:
Examples of how to use these types of views are presented in the section "Using T-SQL to Create a View" later in this chapter.
Views can also be used to consolidate partitioned data. Data in a large table can be partitioned across multiple smaller tables for easier management, and then views can be used to merge these tables into a larger virtual table for easier accessibility.
One advantage of using views is that they always provide up-to-date data. The SELECT statement that defines a view is executed only when the view is accessed, so all changes to the underlying table are reflected in the view.
Another advantage of using views is that a view can have a different security level than that of the underlying table. The query that defines the view is run under the security level of the user who created the view. Thus, you can use a view to mask off data that you do not want certain classes of users to see. We'll look at an example of this feature in the section "Subset of Columns" later in this chapter.
SQL Server places a few restrictions on view creation and use. These restrictions include the following:
NOTE
For more information regarding view restrictions, go to the Books Online Index and look up "Creating a View" and then choose "Creating a View" from the Topics Found dialog box.