1 Chapter 12 Data Manipulation Language (DML) View Dr. Chitsaz Objectives Definition Create a view Retrieve data from a view Insert, delete, update to/from.

Slides:



Advertisements
Similar presentations
Structured Query Language (SQL)
Advertisements

Advanced Piloting Cruise Plot.
Advanced SQL Topics Edward Wu.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 1 The Study of Body Function Image PowerPoint
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
Refreshing Materialized Views
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Exit a Customer Chapter 8. Exit a Customer 8-2 Objectives Perform exit summary process consisting of the following steps: Review service records Close.
Determine Eligibility Chapter 4. Determine Eligibility 4-2 Objectives Search for Customer on database Enter application signed date and eligibility determination.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Year 6 mental test 10 second questions
1 Term 2, 2004, Lecture 6, Views and SecurityMarian Ursu, Department of Computing, Goldsmiths College Views and Security 3.
Dr. Alexandra I. Cristea CS 252: Fundamentals of Relational Databases: SQL5.
SQL: The Query Language Part 2
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
Information Systems Today: Managing in the Digital World
ABC Technology Project
9 Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
Introduction to Structured Query Language (SQL)
1 Web-Enabled Decision Support Systems Access Introduction: Touring Access Prof. Name Position (123) University Name.
9 Creating and Managing Tables. Objectives After completing this lesson, you should be able to do the following: Describe the main database objects Create.
Yong Choi School of Business CSU, Bakersfield
Microsoft Access.
Chapter Information Systems Database Management.
Creating Tables. 2 home back first prev next last What Will I Learn? List and provide an example of each of the number, character, and date data types.
1 Undirected Breadth First Search F A BCG DE H 2 F A BCG DE H Queue: A get Undiscovered Fringe Finished Active 0 distance from A visit(A)
VOORBLAD.
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
Note: A bolded number or letter refers to an entire lesson or appendix. A Adding Data Through a View ADD_MONTHS Function 03-22, 03-23, 03-46,
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
© 2012 National Heart Foundation of Australia. Slide 2.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Chapter 5 Test Review Sections 5-1 through 5-4.
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
25 seconds left…...
Januar MDMDFSSMDMDFSSS
Week 1.
Analyzing Genes and Genomes
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
CpSc 3220 Designing a Database
10 Copyright © 2004, Oracle. All rights reserved. Creating Other Schema Objects.
Copyright © 2004, Oracle. All rights reserved. Lecture 3: Creating Other Schema Objects Lecture 3: Creating Other Schema Objects ORACLE.
11 Copyright © 2007, Oracle. All rights reserved. Creating Other Schema Objects.
1 Chapter Nine Data Manipulation Language (DML) Views Objectives Definition Creating views Retrieve data from a view Drop a view.
11 Copyright © Oracle Corporation, All rights reserved. Creating Views.
Database Programming Sections 11 & 12 – Creating, and Managing Views, Sequences, Indexes, and Synonymns.
Chapter 2 Views. Objectives ◦ Create simple and complex views ◦ Creating a view with a check constraint ◦ Retrieve data from views ◦ Data manipulation.
Database Management COP4540, SCS, FIU Structured Query Language (Chapter 8)
Views. Objectives Create views Modify/Drop Views Insert/Delete/Update to/from views Retrieve data from views.
Chapter 13 Views Oracle 10g: SQL. Oracle 10g: SQL2 Objectives Create a view, using CREATE VIEW command or the CREATE OR REPLACE VIEW command Employ the.
Copyright  Oracle Corporation, All rights reserved. 12 Creating Views.
Copyright س Oracle Corporation, All rights reserved. 12 Creating Views.
What Is a View? EMPNO ENAME JOB EMP Table EMPVU10 View
Chapter 2 Views.
Chapter 2 Views.
Contents Preface I Introduction Lesson Objectives I-2
IST 318 Database Administration
Presentation transcript:

1 Chapter 12 Data Manipulation Language (DML) View Dr. Chitsaz Objectives Definition Create a view Retrieve data from a view Insert, delete, update to/from views Drop a view

2 Views Database Objects 1-TABLE: Physical unite 2-VIEW: Logical representation 3-SEQUENCE 4-SYNONYM 5-INDEX

3 Views VIEW: -What is a view? Logical representations (Subset of data from one or more tables or views) -Why use a view? Restrict database access. Make complex queries easy. Represent data from different tables. Represent different Views of the same data.

4 Creating a View: CREATE [OR REPLACE] [FORCE | NOFORCE] VIEW name AS Subquery [WITH CHECK OPTION [CONSTRAINT name]] [WITH READ ONLY]; Use OR REPLACE if view already exists. Use FORCE if the base tables are not existed (view will be created even if the base table does not exists) Use WITH CHECK OPTION: only rows that accessible by view can be updated. Use WITH READ ONLY for select only Views

5 CREATE VIEW COSCStudent AS SELECT ID, Name, GPA FROM Student WHERE Major=COSC; DESCRIBE COSCStudent; Views

6 Results Name Null? Type ID NOT NULL NUMBER(6) NAME VARCHAR2(80) GPA NUMBER(3,2)

7 Aliases Column Name: CREATE VIEWCOSCStudent AS SELECTID COSCid, name COSCName, GPA FROMStudent WHEREMajor=COSC; Views

8 Retrieving Data from View: SELECT* FROMCOSCStudent; SELECTCOSCid, COSCname FROMCOSCStudent; Views

9 Results COSCID COSCNAMEGPA James John3.32

10 Modifying a View: CREATE OR REPLACE VIEW COSCStudent (Field1, Field2) //alias names for Major and Minor AS SELECTMajor, Minor FROMstudent WHEREmajor =COSC; Views

11 Example: CREATE VIEW COSCData (minsal, maxsal, avgsal) AS SELECTMIN(Salary), MAX (Salary), AVG (Salary) FROMFaculty WHEREdept =COSC; Views

12 SELECT* FROM COSCData; MINSAL MAXSAL AVGSAL

13 Modifying a View (continued): CREATE VIEW studentgrade AS SELECTName, ID, c_num, grade FROMstudent, student_course; CREATE VIEW majors AS SELECTmajor, count (*) total FROMstudent GROUP BYmajor; Views

14 SELECT* FROM majors; MAJOR TOTAL COSC 2 ENGL 1 MATH 4

15 CREATE FORCE VIEW COSCStudent AS SELECT ID, Name, GPA FROM NewStudent WHERE Major=COSC; Views

16 Check Option: CREATE VIEWCOSCStudent AS SELECTID COSCid, name COSCName, GPA FROMStudent WHEREMajor=COSC WITH CHECK OPTION CONSTRAINT cosc_ck; //You can only update the COSC students records. Views

17 Read Only Option: CREATE VIEWCOSCStudent AS SELECTID COSCid, name COSCName, GPA FROMStudent WHEREMajor=COSC WITH READ ONLY; //Data may not be modified Views

18 Removing a View: DROP VIEW majors; Views

19 User Views You can check data dictionary to check for name of view and definition using USER_VIEWS SELECT * FROM USER_VIEWS

20 Rules for Performing DML operation on a View: Simple view: you can perform DML operation on simple view (not complex; droved from more than one table) Can NOT REMOVE a row if view contains: –Group function (aggregated functions including null) –GROUP BY clause (or having) –DISTINCT clause

21 Rules for Performing DML operation on a View: Can NOT MODIFY data in a view if it contains: 1.The Following: Group function GROUP BY clause DISTINCT clause 2.Column defined by expression The ROWNUM pseudocolumn

22 Rules for Performing DML operation on a View: Can NOT ADD data in a view if it contains: 1.The Following: Group function GROUP BY clause DISTINCT clause 2.Column defined by expression 3.NOT NULL columns in the tables that are not selected by view

23 Insert Data Into A View: INSERT INTO COSCStudent (COSCid, COSCName, GPA) VALUES (1121,SANDY,3.33); SELECT COSCid, COSCName, GPA FROM COSCStudent WHERE Major=COSC; Views

24 Viewing constraints: SELECT constraint_name, constraint_type, search_condition, status,last_change FROM user_constraints WHERE table_name=STUDENT; Result: CONSTRAINT_NAME CSTATUS LAST_CHANGE SYS_C P ENABLED 18-NOV-05

25 Viewing constraints: SELECT constraint_name, column_name, owner FROM user_cons_columns WHERE table_name=STUDENT; CONSTRAINT_NAME COLUMN_NAME OWNER SYS_C ID CS640M2 This is list of columns that can be updated USER_UPDATABLE_COLUMNS

26 To improve the performance of an application, you can make local copies of remote tables. Definition: Stored local copies of tables Master table: remote site Local Table: local site Refresh interval: how frequently update the tables You need to have Creating Materialized View Privilege to create materialized view Materialized Views

27 CREATE TABLE local student AS SELECT * Materialized Views

28 Creating a Materialized View: CREATE MATERIALIZED VIEW name [REFRESH clause ] AS Subquery; Materialized Views

29 Creating a Materialized View: Example: CREATE MATERIALIZED VIEW localstudents REFRESH FAST START WITH SYSDATE NEXT SYSDATE+10 WITH PRIMARY KEY AS SELECT * FROM Materialized Views