1 Section 9 - Views, etc. u Part 1: Views u Part 2:Security Issues u Part 3:Transaction Management u Part 4:Set Operations u Part 5:Triggers and Stored.

Slides:



Advertisements
Similar presentations
Manipulating Data Schedule: Timing Topic 60 minutes Lecture
Advertisements

Virtual training week 4 structured query language (SQL)
Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
Dec 15, 2003Murali Mani Transactions and Security B term 2004: lecture 17.
Cs3431 Transactions, Logging and Security. cs3431 Transactions: What and Why? A set of operations on a database must appear as one “unit”. Example: Consider.
Introduction to Structured Query Language (SQL)
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Chapter 5 Data Manipulation and Transaction Control Oracle 10g: SQL
1 Section 5 - Grouping Data u The GROUP BY clause allows the grouping of data u Aggregate functions are most often used with the GROUP BY clause u GROUP.
SQL Basics. SQL SQL (Structured Query Language) is a special-purpose programming language designed from managing data in relational database management.
Agenda Journalling More Embedded SQL. Journalling.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Security, Transactions, and Views. Security Achieved through GRANT & REVOKE Assumes the database can recognize its users and verify their identity can.
Introduction to SQL Steve Perry
Views: Limiting Access to Data A view is a named select statement that is stored in a database as an object. It allows you to view a subset of rows or.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
SQL/Lesson 4/Slide 1 of 45 Using Subqueries and Managing Databases Objectives In this lesson, you will learn to: *Use subqueries * Use subqueries with.
Security, Transactions, and Views. About Security As is the case in most shared environments, the DBMS also must implement a security mechanism that allows.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Views In some cases, it is not desirable for all users to see the entire logical model (that is, all the actual relations stored in the database.) In some.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 7 Introduction to Structured.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Constraints cis 407 Types of Constraints & Naming Key Constraints Unique Constraints Check Constraints Default Constraints Misc Rules and Defaults Triggers.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Security, Transactions, and Views. About Security As is the case in most shared environments, the DBMS also must implement a security mechanism that allows.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
 CONACT UC:  Magnific training   
1 Section 10 - Embedded SQL u Many computer languages allow you to embed SQL statements within the code (e.g. COBOL, PowerBuilder, C++, PL/SQL, etc.) u.
Delete Data Database Administration Fundamentals LESSON 3.4.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
1 Section 8 - Manipulating Data u The INSERT statement adds rows of data to the database u The UPDATE statement changes columns of existing data u The.
1 Section 3 - Select Statement u The Select statement allows you to... –Display Data –Specify Selection Criteria –Sort Data –Group Data for reporting –Use.
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
Oracle sql Online Training By SMART MIND ONLINE TRAINING Website:
Dept. of Computer & Information Sciences
Getting started with Accurately Storing Data
SQL Query Getting to the data ……..
Indexes By Adrienne Watt.
The Basics of Data Manipulation
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
ATS Application Programming: Java Programming
Active Database Concepts
Introduction To Database Systems
ITEC 313 Database Programming
Manipulating Data.
SQL: Advanced Options, Updates and Views Lecturer: Dr Pavle Mogin
What Is a View? EMPNO ENAME JOB EMP Table EMPVU10 View
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
The Basics of Data Manipulation
Data Control Language Grant, Revoke.
Chapter 2 Views.
Chapter 7 Introduction to Structured Query Language (SQL)
C1. SQL BAsic.
Chapter 2 Views.
Oracle9i Developer: PL/SQL Programming Chapter 8 Database Triggers.
Contents Preface I Introduction Lesson Objectives I-2
Chapter 8 Advanced SQL.
Database Design: Relational Model
Chapter 11 Managing Databases with SQL Server 2000
Prof. Arfaoui. COM390 Chapter 9
IST 318 Database Administration
Indexes and more Table Creation
So What are Views and Triggers anyway?
Presentation transcript:

1 Section 9 - Views, etc. u Part 1: Views u Part 2:Security Issues u Part 3:Transaction Management u Part 4:Set Operations u Part 5:Triggers and Stored Procedures u Part 6:Performance Issues u Part 7:Database Integrity

2 Part 1: Views u Views are virtual tables which are created from the result set of a SELECT statement u Views are not separate copies of the data in the tables from which they are derived

3 Views -Continued u A View is essentially stored SQL Select statement u A View is named like a table when created (e.g. books_and_publishers)

4 Create VIEW Syntax u CREATE VIEW view_name [column_name [,column_name] … ] AS select_statement;

5 Example - Create View u CREATE VIEW books_and_publishers AS (SELECT title, pub_name FROM titles t, publishers p WHERE t.pub_id = p.pub_id);

6 What the User Sees u SELECT title, pub_name FROM books_and_publishers; u Statement first executes the SELECT associated with the View u User Select is against the View results (which are transparent to the User)

7 Why Views? u Saves the user from complex joins u Stops the user from seeing secure data

8 Deleting Views from the Database u DROP VIEW books_and_publishers; u Warning: If you DROP a table that the VIEW depends upon, the VIEW will no longer work

9 Naming View Columns u Assign alias names to View columns is optional… in most cases. u By default, VIEW will use the same columns names returned from the SELECT u Exceptions: If there is any ambiguity from a Join operation or View column is arithmetically derived u If you rename any columns, you must rename all of them!

10 Exercise u Create a view that displays the authors names, social security number and the average position they appear on the books they've written.

11 Solution u CREATE VIEW authors_position (ssn, lastn, firstn, average_order) AS SELECT a.au_id, au_lname, au_fname, AVG(au_ord) FROM authors a, titleauthors ta WHERE a.au_id = ta.au_id GROUP BY a.au_id, au_lname, au_fname;

12 Part 2: Security Issues u Two basic SQL security statements… –GRANT gives a user access rights to a table or columns on a table –REVOKE removes user access right to a table or columns on a table

13 GRANT/REVOKE Syntax u GRANT {ALL | privilege_list } ON table or view name [column_list] TO {PUBLIC | user_list} u REVOKE {ALL | privilege_list } ON table or view name [column_list] FROM {PUBLIC | user_list}

14 Examples u GRANT INSERT, UPDATE ON titles TO perrys, smithj; u REVOKE UPDATE ON titles(advance, price) FROM jonesk;

15 Views to restrict access u Payroll table: name, ssn, dept, salary u CREATE VIEW payroll_generalaccess (name, dept) AS SELECT name, dept FROM payroll;

16 Vendors Offer Security Extensions u ORACLE has GROUPs –allows you group user_ids under a group –allows you to assign access rights to that group

17 Exercise u Give the user ids perrys and landeyt the ability to make changes to existing data on the authors table (except the au_id column) and to add new rows of data but not delete them. Of course, they should be able to see the data.

18 Part 3: Transaction Management u A transaction is a logical unit of work u Transaction management means ensuring that a set of SQL statements is treated as a unit u Transaction management guarantees the either all the operations are completed or none of them are

19 Savings Changes to the Database u COMMIT statement saves all the changes made to the database since the last COMMIT. u ROLLBACK statement un-does all changes made to the database since the last COMMIT or ROLLBACK.

20 Example u Banking transaction: –Transfer $100 from Savings to Checking –First reduce the savings balance by $100 –Then increase the checking balance by $100 u What happens if the system crashes after reducing the savings balance, but before increasing the checking balance?

21 Status Checking u When SQL is embedded in computer applications, you must check for the success or failure of each SQL statement u You COMMIT changes only after all the SQL statements have completed successfully in a transaction.

22 Concurrency Control u How do you prevent simultaneous transactions on the same data from interfering with each other? u Concurrency control means making sure that data is never operated on by another user until a change is completed

23 The Lost Update Problem u Steve calls travel agent for a ticket to Tahiti u Agent checks computer: One ticket left u While I think about: Barbara calls her ticket agent and asks for a ticket to Tahiti u Her agent check computer: One ticket left u Steve buys ticket: Agent saves information u Barbara buys ticket: Agent saves information u Steve goes to the airport for his ticket…Who?

24 Row Locking is the Solution u When Steve's agent bring up the record a 'write' lock is placed u After, Steve's agent saves the transaction the lock is removed u When Barbara's agent tries to save, warned that the record has changed and must re- retrieve it. u When retrieved again, Barbara will be informed that the ticket has been sold.

25 Locking in Oracle u SELECT au_id, city FROM authors WHERE au_id = ' ' FOR UPDATE OF city; u Places a write lock on the column city for the row with a Primary key of ' '

26 Part 4: Set Operations u SQL operates on Sets of row (i.e. Relations) u We perform mathematical Set operations on result sets

27 Oracle SET operators u UNION –combines all rows returned from each result set with an implicit DISTINCT u INTERSECT –combines only the rows that are in common to each result set u MINUS –Subtracts the rows from the first result set that are found in the second result set

28 Example u List all the authors and editors SELECT au_lname, au_fname FROM authors UNION SELECT ed_lname, ed_fname FROM editors;

29 Matching Select Lists u To perform SET operations the select lists must match from ALL result sets u They must have the same number of columns and the data types must match

30 Part 5: Triggers & Procedures u Triggers –Automatic updates set up to execute when an INSERT, UPDATE, or DELETE is performed against a table u Stored Procedures –Precompiled SQL statements that reside on the database server and may receive arguments and return data. May use procedural language –Generally called from within computer applications or Triggers

31 Example u CREATE TRIGGER record_users ON authors FOR UPDATE AS ;

32 Part 6: Performance Issues u Indexes u Database de-normalization u Vendor specific optimization tools –e.g. Oracle Analyzer, Hints u Use of Views to force limits on result size

33 Part 7: Database Integrity u Domain Constraints Integrity –Set of potential values for a column u Entity Integrity –e.g. No primary keys with NULL status u Referential Integrity –Logical consistency between Primary Keys and Foreign Keys. No Orphans.

34 Last Slide - Section 9 u Please complete Assignment 8