Beginning SQL
Beginning SQL Beginning SQL
10 Views Views, as the name implies, are queries used to provide users with a specific view of the data in the database. In doing so, views serve a variety of purposes. They may tie related tables together and then pull selected fields out that specific users need, or they may pull selected interesting rows of data from a table that contains other rows of no interest to specific users. They may summarize large data sets, returning averages, counts, and the like. Relational databases are sets of data in tables, which, taken alone, are rarely of any use to anyone. Views allow the database administrator (DBA) to pull fields of interest from tables of interest and return a coherent data set useful to some specific user or application. In this chapter, you learn how to build and save views for reuse, how to use views to tie related data back together, how to use views to narrow or limit the data that users are allowed to see, and how views may be used for security purposes. Introducing Views A normalized database is created by designing tables for each object or event being modeled, with the fields of each table representing an attribute of the object or event. Once the developer creates the normalized structure, it becomes necessary to allow users to view specific pieces of data. The users rarely understand the structure, so the DBA is often tasked with building the views that various users require. A view is nothing more than a SQL statement that is stored in the database with an associated name. Views allow the DBA to do the following: ❑ Structure data in a way that users or classes of users find natural or intuitive ❑ Restrict access to the data such that a user can see and (sometimes) modify exactly what they need and no more ❑ Simplify the DBA’s job by building base data structures that the DBA can use to build other views in a natural progression ❑ Summarize data for reports
- Page 562: Summary Queries within Queries This
- Page 568: Chapter 9 264 Figure 9-1 The SQL ne
- Page 572: Chapter 9 266 INSERT INTO OrderItem
- Page 576: Chapter 9 268 VALUES (5,7, 2,’200
- Page 580: Chapter 9 Now that you’ve added t
- Page 584: Chapter 9 272 FirstName LastName Mo
- Page 588: Chapter 9 274 DVDPrice column is in
- Page 592: Chapter 9 SalesPersonId FirstName L
- Page 596: Chapter 9 278 SalesPersonId MemberI
- Page 600: Chapter 9 280 SalesPersonId MemberI
- Page 604: Chapter 9 282 MemberDetails.FirstNa
- Page 608: Chapter 9 284 The query would work
- Page 612: Chapter 9 Exercises 286 Assume that
- Page 618: Try It Out Building a View 1. The p
- Page 622: FROM dbo.MemberDetails INNER JOIN d
- Page 626: For example, you might want a list
- Page 630: However, if you take the case of Me
- Page 634: However, someone writes a query tha
- Page 638: Summary As you learned, views are l
- Page 644: Chapter 11 The information that fol
- Page 648: Chapter 11 This SQL adds formats (d
- Page 652: Chapter 11 TRANSACTION statement is
- Page 656: Chapter 11 Additionally, if a DBMS
- Page 660: Chapter 11 ROLLBACK TRANSACTION 310
10<br />
Views<br />
Views, as the name implies, are queries used to provide users with a specific view of the data in<br />
the database. In doing so, views serve a variety of purposes. They may tie related tables together<br />
and then pull selected fields out that specific users need, or they may pull selected interesting<br />
rows of data from a table that contains other rows of no interest to specific users. They may summarize<br />
large data sets, returning averages, counts, and the like. Relational databases are sets of<br />
data in tables, which, taken alone, are rarely of any use to anyone. Views allow the database<br />
administrator (DBA) to pull fields of interest from tables of interest and return a coherent data set<br />
useful to some specific user or application.<br />
In this chapter, you learn how to build and save views for reuse, how to use views to tie related<br />
data back together, how to use views to narrow or limit the data that users are allowed to see, and<br />
how views may be used for security purposes.<br />
Introducing Views<br />
A normalized database is created by designing tables for each object or event being modeled, with<br />
the fields of each table representing an attribute of the object or event. Once the developer creates<br />
the normalized structure, it becomes necessary to allow users to view specific pieces of data. The<br />
users rarely understand the structure, so the DBA is often tasked with building the views that various<br />
users require. A view is nothing more than a <strong>SQL</strong> statement that is stored in the database with<br />
an associated name. Views allow the DBA to do the following:<br />
❑ Structure data in a way that users or classes of users find natural or intuitive<br />
❑ Restrict access to the data such that a user can see and (sometimes) modify exactly what<br />
they need and no more<br />
❑ Simplify the DBA’s job by building base data structures that the DBA can use to build<br />
other views in a natural progression<br />
❑ Summarize data for reports