13
1 Chapter Nine Data Manipulation Language (DML) Views Objectives Definition Creating views Retrieve data from a view Drop a view

1 Chapter Nine Data Manipulation Language (DML) Views Objectives Definition Creating views Retrieve data from a view Drop a view

Embed Size (px)

Citation preview

Page 1: 1 Chapter Nine Data Manipulation Language (DML) Views Objectives Definition Creating views Retrieve data from a view Drop a view

1

Chapter Nine Data Manipulation Language (DML)Views

Objectives Definition Creating views Retrieve data from a view Drop a view

Page 2: 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.

Page 3: 1 Chapter Nine Data Manipulation Language (DML) Views Objectives Definition Creating views Retrieve data from a view Drop a view

3

CREATE VIEW COSCStudent AS

SELECT ID, Name, GPAFROM StudentWHERE Major=‘COSC’;

DESCRIBE COSCStudent;

VIEWSDATABASE OBJECTS

Page 4: 1 Chapter Nine Data Manipulation Language (DML) Views Objectives Definition Creating views Retrieve data from a view Drop a view

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

Page 5: 1 Chapter Nine Data Manipulation Language (DML) Views Objectives Definition Creating views Retrieve data from a view Drop a view

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

Page 6: 1 Chapter Nine Data Manipulation Language (DML) Views Objectives Definition Creating views Retrieve data from a view Drop a view

6

Aliases Column Name:CREATE VIEW COSCStudent

ASSELECT ID COSCid,

name COSCName,GPA

FROM StudentWHERE Major=‘COSC’;

VIEWSDATABASE OBJECTS

Page 7: 1 Chapter Nine Data Manipulation Language (DML) Views Objectives Definition Creating views Retrieve data from a view Drop a view

7

Retrieving Data from View:SELECT *FROM COSCStudent;

SELECT COSCid, COSCnameFROM COSCStudent;

VIEWSDATABASE OBJECTS

Page 8: 1 Chapter Nine Data Manipulation Language (DML) Views Objectives Definition Creating views Retrieve data from a view Drop a view

8

Practice:Display all the fields in Cust_Sale_v

Page 9: 1 Chapter Nine Data Manipulation Language (DML) Views Objectives Definition Creating views Retrieve data from a view Drop a view

9

Example:CREATE VIEW COSCData

(minsal, maxsal, avesal)AS

SELECT MIN(salary), MAX (salary), AVG (salary)

FREOM facultyWHERE dept =‘COSC’;

VIEWSDATABASE OBJECTS

Page 10: 1 Chapter Nine Data Manipulation Language (DML) Views Objectives Definition Creating views Retrieve data from a view Drop a view

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

Page 11: 1 Chapter Nine Data Manipulation Language (DML) Views Objectives Definition Creating views Retrieve data from a view Drop a view

11

Removing a View:DROP VIEW majors;

VIEWSDATABASE OBJECTS

Page 12: 1 Chapter Nine Data Manipulation Language (DML) Views Objectives Definition Creating views Retrieve data from a view Drop a view

12

Practice:Remove the view Cust_v

Page 13: 1 Chapter Nine Data Manipulation Language (DML) Views Objectives Definition Creating views Retrieve data from a view Drop a view

13

Practice:Create a view using a sub-query.