Upload
myron-phelps
View
212
Download
0
Embed Size (px)
Citation preview
1
Chapter Nine Data Manipulation Language (DML)Views
Objectives Definition Creating views Retrieve data from a view Drop a view
2
VIEWSDATABASE OBJECTS
1-TABLE2-VIEW
-What is a view?-Why using a view?
Restrict database access.Make complex queries easy.Represent data from different
tablesRepresent different Views of the
same data.
3
CREATE VIEW COSCStudent AS
SELECT ID, Name, GPAFROM StudentWHERE Major=‘COSC’;
DESCRIBE COSCStudent;
VIEWSDATABASE OBJECTS
4
Practice:Create a view called Customer_v with the attributes:
-Customer number-Customer last name-Customer Street-Customer City-Customer State -Customer zip code
5
Practice:Create a view for customer sales person called Cust_Sale_v with the attributes:
-Customer number-Customer last name-Sales Rep Number-Sales Person First Name-Sales Person Last Name
6
Aliases Column Name:CREATE VIEW COSCStudent
ASSELECT ID COSCid,
name COSCName,GPA
FROM StudentWHERE Major=‘COSC’;
VIEWSDATABASE OBJECTS
7
Retrieving Data from View:SELECT *FROM COSCStudent;
SELECT COSCid, COSCnameFROM COSCStudent;
VIEWSDATABASE OBJECTS
8
Practice:Display all the fields in Cust_Sale_v
9
Example:CREATE VIEW COSCData
(minsal, maxsal, avesal)AS
SELECT MIN(salary), MAX (salary), AVG (salary)
FREOM facultyWHERE dept =‘COSC’;
VIEWSDATABASE OBJECTS
10
Practice:Create a view called Cust_v with the attributes:
-Customer number-Customer name (Last, First)-Customer Address (Street, city, state, zip)-Customer balance-Customer credit limit-Sales Rep Number
11
Removing a View:DROP VIEW majors;
VIEWSDATABASE OBJECTS
12
Practice:Remove the view Cust_v
13
Practice:Create a view using a sub-query.