The document introduces views in databases, explaining that views allow querying data from tables without storing the data themselves. Views can simplify permissions, organize exports, and hide complex structures by presenting query results as virtual tables. The document covers how to create, alter, drop, and get information on views, as well as the advantages of using views in a database.
7. Example of a Views This example shows creating a view called ‘ViewPublishers’ from the Publishers table. This view contains two columns ‘Pubid’ and ‘Pubname’ which are taken from the table. The actual data will be in the Publishers table, which can be viewed and manipulated from the ‘ViewPublishers’ view. Publishers PARIS IL Chicago Five lake 1622 USA CA Berkely Algodata 1389 USA DC Washington Binnet 0877 CHICAGO MA Boston New Moon 0736 Country State City Pubname Pubid ViewPublishers Five lake 1389 Algodata 0877 Binnet 0736 Pubname Pubid
Faculty Notes: Views are virtual tables (tables which don’t occupy memory) whose contents are taken or derived from other tables. Just like other table, a view consists of rows with columns, and you can retrieve data from a view. Views can be used to join two tables in database and present the underlying data as if the data were coming from a single table Views can be used as a security mechanism to restrict the data available to end users Views can also be used to aggregate data
Faculty Notes: A VIEW is basically a table that only exists when you use the view in a query. It is considered a virtual table because it acts like a table in the sense that the operations that can be performed on a table can be performed on a view. This virtual table does not exist in the database. It gets created when we use the view and then deleted. The named VIEW is the only thing that persists.
Faculty Notes: Views make your life easier by simplifying your complex queries into a simple command. You won’t have to create complicated joins and subqueries repeatedly when you create a view instead. Your view hides the complexity of the underlying query. You can create views that hide information that isn’t needed by the user. You can allow users to see just the information they need, while keeping the sensitive information hidden using a view.
Faculty Notes: Focuses data for users : It can be used as security mechanism by allowing user to access data through view, without granting permission to directly access the base table. Hides data complexity : Views hide the complexity of the database design from the user. This enables developers to change database design without affecting user interaction with the database. Simplifies permission management : Instead of granting permission to users for querying specific columns of the base tables,database owners can grant them permission for querying data only through views. Organizes data for export to other applications : User can create view based on a complex query that joins two or more tables. This appears to the user as single table. Reduces object size: views do not contain data, server stores only the definition of the view in the database
Faculty Notes: Instructor has to Use inbuilt database table Database: Pubs Tables Publishers
Faculty Notes: The example creates a simple view ViewPublisher which selects all the data from Publisher Table.
Faculty Notes: The syntax of Complex view is similar to Create View Complex view is a view which normally contains GROUP BY as well as joins. Data in the underlying tables cannot be updated using Complex views.
Faculty Notes: The “With Check option” clause specifies that Inserts and Updates performed through the View are not allowed to create rows which the view cannot select, and therefore allows integrity constraints and data validation checks to be enforced on data begin Inserted or Updated. For instance, Through this view you would not be able to insert data where deptno is anything other that 30.
Faculty Notes: If you need to change the view itself without losing on it’s name along with the permissions set for the view, you may choose to alter the view rather than deleting the existing view and creating a new view with the same name.
Faculty notes: There are some system stored procedures that help retrieve information on views . sp_help: This system stored procedure displays view related information. sp_depends: Determines the dependencies by looking at the sys.sql_dependencies view. sp_helptext: Retrieves and displays the view definition.The object must be in the current database.
Faculty Notes: sp_columns: This stored procedure is equivalent to SQLCOLUMS in ODBC.