© 2007 by Prentice Hall4-1 Introduction to Oracle 10g Chapter 4 Modifying Data and Auditing Table Operations James Perry and Gerald Post.

Slides:



Advertisements
Similar presentations
1 Constraints, Triggers and Active Databases Chapter 9.
Advertisements

Virtual training week 4 structured query language (SQL)
SQL Review Sections 1 - SQL and other basic statements.
A Guide to SQL, Seventh Edition. Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT.
8 Copyright © Oracle Corporation, All rights reserved. Manipulating Data.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-1 COS 346 Day 17.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Chapter 5 Data Manipulation and Transaction Control Oracle 10g: SQL
+ Structured Query Language Part 2 KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 David M. Kroenke’s Chapter Seven: SQL for Database Construction and.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
I Copyright © 2004, Oracle. All rights reserved. Introduction.
Introduction to SQL Steve Perry
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 DB2 9 Fundamentals.
© 2007 by Prentice Hall3-1 Introduction to Oracle 10g Chapter 3 Creating, Modifying, Renaming, and Deleting Database Tables James Perry and Gerald Post.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
4 Copyright © 2006, Oracle. All rights reserved. Restricting and Sorting Data.
Chapter 6 Additional Database Objects Oracle 10g: SQL.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
1 Copyright © 2006, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
SQL (DDL & DML Commands)
© 2007 by Prentice Hall6-1 Introduction to Oracle 10g Chapter 6 Creating Multitable Queries and Views James Perry and Gerald Post.
1 © Prentice Hall, 2002 Chapter 8: Advanced SQL Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden.
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
ITBIS373 Database Development Lecture 3a - Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
1 ISYS Triggers. 2 Agenda Triggers Review Correlation identifiers (pseudo records) Restrictions on triggers Trigger usage Mutating tables Enabling.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
© 2007 by Prentice Hall8-1 Introduction to Oracle 10g Chapter 8 Understanding and Using Forms Builder James Perry and Gerald Post.
Advanced SQL: Triggers & Assertions
1 Chapter 7 Triggers and Active Databases. 2 Trigger Overview Element of the database schema General form: ON IF THEN –Event- request to execute database.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
Chapter 9 Constraints. Chapter Objectives  Explain the purpose of constraints in a table  Distinguish among PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK,
Oracle 11g: SQL Chapter 4 Constraints.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Objectives Database triggers and syntax
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 9 Database Triggers.
© 2007 by Prentice Hall7-1 Introduction to Oracle 10g Chapter 7 Using PL/SQL to Your Advantage James Perry and Gerald Post.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
PL/SQLPL/SQL Oracle11g: PL/SQL Programming Chapter 9 Database Triggers.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 9 Database Triggers.
Working with Columns, Characters, and Rows. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Apply the concatenation.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
© 2007 by Prentice Hall2-1 Introduction to Oracle 10g Chapter 2 Overview of SQL and SQL*Plus James Perry and Gerald Post.
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
Chapter 12Introduction to Oracle9i: SQL1 Chapter 12 Additional Database Objects.
IMS 4212: Constraints & Triggers 1 Dr. Lawrence West, Management Dept., University of Central Florida Stored Procedures in SQL Server.
Manipulating Data Lesson 3. Objectives Queries The SELECT query to retrieve or extract data from one table, how to retrieve or extract data by using.
Chapter 13 Triggers. Trigger Overview A trigger is a program unit that is executed (fired) due to an event Event such as updating tables, deleting data.
A Guide to MySQL 6. 2 Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT command.
CSCI N311: Oracle Database Programming 5-1 Chapter 15: Changing Data: insert, update, delete Insert Rollback Commit Update Delete Insert Statement –Allows.
Unit-8 Introduction Of MySql. Types of table in PHP MySQL supports various of table types or storage engines to allow you to optimize your database. The.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Chapter 13 Triggers. Trigger Overview A trigger is a program unit that is executed (fired) due to an event Event such as updating tables, deleting data.
 CONACT UC:  Magnific training   
Murali Mani Constraints. Murali Mani Keys: Primary keys and unique CREATE TABLE Student ( sNum int, sName varchar (20), dept char (2), CONSTRAINT key.
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.
ISYS Triggers.
Creating Database Triggers
Agenda Triggers Review Correlation identifiers (pseudo records)
ISYS Triggers.
Advanced SQL: Views & Triggers
Manipulating Data.
Oracle9i Developer: PL/SQL Programming Chapter 8 Database Triggers.
Contents Preface I Introduction Lesson Objectives I-2
Prof. Arfaoui. COM390 Chapter 9
Manipulating Data Lesson 3.
Restricting and Sorting Data
Presentation transcript:

© 2007 by Prentice Hall4-1 Introduction to Oracle 10g Chapter 4 Modifying Data and Auditing Table Operations James Perry and Gerald Post

© 2007 by Prentice Hall4-2 Chapter Outline Inserting Rows into Tables Updating Data Deleting Rows and Truncating Tables Merging Rows Database Transactions Creating and Using Database Triggers

© 2007 by Prentice Hall4-3 Table 4.1 Constraints and structure of the Agents table ColumnDescriptionData typeConstraint(s) AgentIDUnique number assigned to each agent INTEGERPrimary key GenderAgent’s sexNVARCHAR2(10)Check: only ‘M’, ‘m’, ‘F’ or ‘f’ TitleInternal title assigned to each employee NVARCHAR2(20)Check: only ‘salesperson’ or ‘broker’ (any combination of upper- and lowercase letters allowed) LicenseStatusIDCode representing an agent’s real estate license status INTEGERForeign key; value must be found in the LicenseStatus table’s primary key column, LicenseStatusID

© 2007 by Prentice Hall4-4 Table 4.2 Common date format model symbols Format Model SymbolDisplayed or Input Value MONTH Month MM FEBRUARY February 02 DD15 DDD251 DAY Day DY WEDNESDAY Wednesday WED YYYY YY

© 2007 by Prentice Hall4-5 Table 4.3 Oracle’s relational operators Relational OperatorMeaning =Equal to <> or !=Not equal to >Greater than <Less than <=Less than or equal to >=Greater than or equal to

© 2007 by Prentice Hall4-6 Table 4.4 Oracle’s logical operators Logical OperatorMeaningWHERE Clause Example ANDTrue only if both conditions are true; false otherwise WHERE State = ‘MN’ AND Gender = ‘M’ ORTrue if either condition is true; false otherwise WHERE LicenseStatusID = 1001 OR LicenseStatusID = 1002 NOTNegate expressionWHERE NOT State = ‘NE’ INTrue if among set of discrete values listed WHERE City IN(‘Arcata’, ‘Fortuna’, ‘Orick’) LIKEWildcard expression allowing “don’t care” conditions WHERE LastName LIKE ‘Mc%’ BETWEEN … AND … True if within the value range, inclusive WHERE SqFt BETWEEN 1500 AND 2000

© 2007 by Prentice Hall4-7 Table 4.5 Annual bonus schedule based on employment longevity Length of service (months)Annual bonus amount 12 or less$0 13 to 24$ to 48$ to 72$1, or greater$1,500

© 2007 by Prentice Hall4-8 Table 4.6 Values supplied in trigger body by correlation names NEW and OLD SQL StatementCorrelation NameValue INSERTNEWValue supplied for the column in the statement that originated the transaction. OLDNULL UPDATENEWValue supplied for the column in the statement that originated the transaction. OLDValue of the column that was last committed into the table prior to the transaction. DELETENEWNULL OLDValue of the column that was last committed into the table before the transaction.

© 2007 by Prentice Hall4-9 Table 4.7 Columns available in the user_triggers data dictionary view Column nameData typeMeaning Trigger_NameVARCHAR2(30)Name of trigger Trigger_TypeVARCHAR2(16)Type of trigger Triggering_EventVARCHAR2(227)Event that causes trigger to fire Table_OwnerVARCHAR2(30)User who owns the table that the trigger references Base_Object_TypeVARCHAR2(16)Type of object referenced by the trigger Table_NameVARCHAR2(30)Table referenced by the trigger Column_NameVARCHAR2(4000)Column referenced by the trigger Referencing_NamesVARCHAR2(128)Name of the OLD and NEW aliases. When_ClauseVARCHAR2(4000)Trigger condition WHEN clause StatusVARCHAR2(8)Whether the trigger is enabled or disabled DescriptionVARCHAR2(4000)Description of trigger Action_TypeVARCHAR2(11)Action type of the trigger Trigger_BodyLONGCode contained in trigger body

© 2007 by Prentice Hall Structure of two related Redwood Realty tables AgentID(primary key) FirstName LastName HireDate BirthDate Gender WorkPhone CellPhone HomePhone Title TaxID LicenseID LicenseDate LicenseExpire LicenseStatusID(foreign key) LicenseStatusID(primary key) StatusText LicenseStatus tableAgents table

© 2007 by Prentice Hall Inserting rows into the Agents table

© 2007 by Prentice Hall Correcting an integrity constraint violation

© 2007 by Prentice Hall Displaying the contents of the LicenseStatus table

© 2007 by Prentice Hall Displaying selected columns from the Agents table

© 2007 by Prentice Hall Inserting date values into a table

© 2007 by Prentice Hall Inserting rows from another table

© 2007 by Prentice Hall Creating a sequence and displaying its characteristics

© 2007 by Prentice Hall Reviewing sequence values and CURRVAL

© 2007 by Prentice Hall Updating multiple columns in a single row

© 2007 by Prentice Hall Updating multiple rows with a single expression

© 2007 by Prentice Hall Selected Agents rows before being updated

© 2007 by Prentice Hall Selected Agents rows after updating them

© 2007 by Prentice Hall Running a SQL statement containing substitution variables

© 2007 by Prentice Hall Processing substitution variables

© 2007 by Prentice Hall Displaying updated table

© 2007 by Prentice Hall Deleting selected rows from a table

© 2007 by Prentice Hall Truncating the Agents table

© 2007 by Prentice Hall MERGE example LicenseStatus target table UpdateLicenseStatus source table LicenseStatus table following MERGE updated columns (bold) Inserted rows (bold) MERGE

© 2007 by Prentice Hall Issuing MERGE to modify a table

© 2007 by Prentice Hall Illustration of transactions Time INSERT …DELETE …INSERT …UPDATE …COMMIT; INSERT … DROP TABLE… Transaction

© 2007 by Prentice Hall Using savepoints in a transaction creating a savepoint change rolled back to latest savepoint

© 2007 by Prentice Hall Modifying the Agents table

© 2007 by Prentice Hall Ending a transaction with COMMIT

© 2007 by Prentice Hall Creating a sequence and a BEFORE INSERT trigger

© 2007 by Prentice Hall Displaying Agents rows with trigger-supplied primary key values

© 2007 by Prentice Hall Creating an audit table and an AFTER UPDATE trigger

© 2007 by Prentice Hall Displaying the audit table

© 2007 by Prentice Hall A trigger execution error

© 2007 by Prentice Hall Correctly executing a statement-level trigger Output produced by statement-level trigger.

© 2007 by Prentice Hall Displaying trigger information