asp.net.ph

Skip Navigation LinksHome > Data Access / ADO.NET > Understanding and Using Views > Comparison of Queries and Views

Understanding and Using Views

Accessing Data with ADO.NET


Comparison of Queries and Views

While views and queries may seem similar, some notable differences exist. This section briefly compares queries and views.

  • Views are stored as part of a database design, but queries are not. As you design a database, you can include views in the design for the following reasons:

    • Design subsets of data that are of interest to different users. Views allow you to establish particular subsets of data that can be assigned to and used by different users and roles.
    • Design views to secure base tables. You can disallow all user access to database tables, requiring users to manipulate data through views only. Such an approach can protect users and application programs from certain database modifications.
  • Query plan generation. A query plan is an internal strategy by which a database server tries to create result sets quickly. A database server can establish a query plan for a view as soon as the view is saved. For a query, however, a database server cannot establish a query plan until the query is actually run — that is, until the user explicitly demands the result set.

  • Updating results. The restrictions on updating result sets are different for views and queries. For more information, see Rules for Updating Results in SQL Server™ Books Online.

  • Sorting results. You can sort any query result, but you can sort a view only if the view includes the TOP clause. For more information about the TOP clause, see Limiting Result Sets Using TOP and PERCENT in SQL Server™ Books Online.

  • Parameterization. You can create parameters for a query, but not for a view. For more information about parameterized queries, see Creating General Purpose Queries in SQL Server™ Books Online.

  • Encryption. A view can be encrypted, but a query cannot. For more information, see Encrypting Views in SQL Server™ Books Online.

Conclusion

Well, that's about it for this session. Hopefully, this article has at least shed some basic insight to help you get started using views in your Web apps.

Views are not limited to what has been covered, though, and are capable of supporting the processing requirements of the largest Web sites and enterprise data-processing systems.

For information on the more advanced aspects of implementing views, such as improving performance using unique clustered indexed views, updateable distributed partitioned views, and symmetric or assymetric partitioned views that can be implemented in databases that are spread across clustered or high availability federated servers, see your SQL Server™ Books Online.

See Also


Back to top


© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note