Assignment 8
Objectives :-To create views.
Views can be thought of as stored queries, which allow us to create a database object that functions very similarly to a table, but whose contents dynamically reflect the selected rows. Views are very flexible; you mayuse a view to address common simple queries to a single table, as well as for complicated ones which may spanacross several tables.
Creating a View :
CREATE [ OR REPLACE ] [ TEMP | TEMPORARY ] VIEW name [ ( column_name [, ...] )
] AS query
CREATE VIEW defines a view of a query. The view has no physical existence, but is dynamically created whenever it is referenced in a query. CREATE OR REPLACE VIEW replaces an existing view of same name. The new query must use the same column names in the same order and with the same data types, but it may add additional columns to the end of the list.
Schema name ( CREATE VIEW myschema.myview ) must be specified to create a view in schema other than the current schema. The TEMPORARY or TEMP parameter is specified to create Temporary views, however If any of the tables referenced by the view are temporary, the view is created as a temporary view (whether TEMPORARY isspecified or not). Temporary views exist in a special schema, so a schema name cannot be given when creating a temporary view. View names should be distinct.
Name: Name (optionally schema-qualified) of a view to be created.
column_name: An optional list of names to be used for columns of the view. If not given, the column names are deduced from the query.
Query:
A SELECT :-
command which will provide the columns and rows of the view.
Example to create a view consisting of all comedy films
CREATE VIEW comedies AS
SELECT *
FROM films
WHERE type = 'Comedy';
ALTER VIEW :-
statement is used to change the definition of a view.
ALTER VIEW name ALTER [ COLUMN ] column SET DEFAULT expression
ALTER VIEW name ALTER [ COLUMN ] column DROP DEFAULT
DROP VIEW :-
statement is used to remove a view
DROP VIEW [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]
Set A
Using the Bank database
1. Create a view which contains the details of all customers who have applied for a loan more than Rs.100000.
2. Create a view which contains details of all loan applications from the ‘Sadashiv peth’ branch.
3. Write the following Queries, on the above created views :
a. List the details of customers who have applied for a loan of Rs. 500000.
b. List the details of loan applications fromSadashiv peth , where loan amount is > Rs 50000.
c. List the details of Loan applications, with the same loan amount.
We have already created the Bank Database so We will use it as it is .
bank4=# select * from Customer;
c_no | c_name | c_add | c_city
------+----------------------+-------------------------------------+----------------------
1 | Raj | Laxmiroad | Pune
2 | Disha | Churchgate | Mumbai
3 | Mahesh | Marketyard | Pune
4 | Jay | ABC road | Nashik
5 | Preeti | XYZ road | Nagar
6 | Kartik | Thane | Mumbai
(6 rows)
bank4=# select * from Loan_app;
l_no | l_amt_required | l_amt_approved | l_date
------+----------------+----------------+------------
121 | $50,000.00 | $45,000.00 | 2010-09-15
131 | $75,000.00 | $60,000.00 | 2005-09-07
141 | $100,000.00 | $80,000.00 | 1999-11-27
151 | $200,000.00 | $150,000.00 | 2012-04-19
161 | $500,000.00 | $450,000.00 | 2006-12-08
171 | $300,000.00 | $250,000.00 | 2005-12-04
181 | $500,000.00 | $350,000.00 | 2002-12-08
191 | $50,000.00 | $40,000.00 | 2012-06-18
bank4=# select * from B_C_L;
br_id | c_no | l_no
-------+------+------
101 | 3 | 141
101 | 1 | 161
102 | 1 | 171
102 | 6 | 151
103 | 2 | 121
103 | 5 | 161
103 | 4 | 131
104 | 2 | 131
(8 rows)
SET B
Using Project-Employee database
2. Create a view containing the project name, project type and start date of the project and should be sorted by start date of the project.
3. Write the following Queries, on the above created views :
a. List different qualifications of employees.
b. List the name and type of projects started on 1st April 2014.
c. List the names of employees who are qualified as Engineers.
the dbms assignment looks good but it should add some images for better explanation
ReplyDeletehttps://www.ideakard.com/