Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "© 2007 by Prentice Hall4-1 Introduction to Oracle 10g Chapter 4 Modifying Data and Auditing Table Operations James Perry and Gerald Post."— Presentation transcript:

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

2 © 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

3 © 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

4 © 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 2005 05

5 © 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

6 © 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

7 © 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$500 25 to 48$700 49 to 72$1,000 73 or greater$1,500

8 © 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.

9 © 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

10 © 2007 by Prentice Hall4-10 4.1 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

11 © 2007 by Prentice Hall4-11 4.2 Inserting rows into the Agents table

12 © 2007 by Prentice Hall4-12 4.3 Correcting an integrity constraint violation

13 © 2007 by Prentice Hall4-13 4.4 Displaying the contents of the LicenseStatus table

14 © 2007 by Prentice Hall4-14 4.5 Displaying selected columns from the Agents table

15 © 2007 by Prentice Hall4-15 4.6 Inserting date values into a table

16 © 2007 by Prentice Hall4-16 4.7 Inserting rows from another table

17 © 2007 by Prentice Hall4-17 4.8 Creating a sequence and displaying its characteristics

18 © 2007 by Prentice Hall4-18 4.9 Reviewing sequence values and CURRVAL

19 © 2007 by Prentice Hall4-19 4.10 Updating multiple columns in a single row

20 © 2007 by Prentice Hall4-20 4.11 Updating multiple rows with a single expression

21 © 2007 by Prentice Hall4-21 4.12 Selected Agents rows before being updated

22 © 2007 by Prentice Hall4-22 4.13 Selected Agents rows after updating them

23 © 2007 by Prentice Hall4-23 4.14 Running a SQL statement containing substitution variables

24 © 2007 by Prentice Hall4-24 4.15 Processing substitution variables

25 © 2007 by Prentice Hall4-25 4.16 Displaying updated table

26 © 2007 by Prentice Hall4-26 4.17 Deleting selected rows from a table

27 © 2007 by Prentice Hall4-27 4.18 Truncating the Agents table

28 © 2007 by Prentice Hall4-28 4.19 MERGE example LicenseStatus target table UpdateLicenseStatus source table LicenseStatus table following MERGE updated columns (bold) Inserted rows (bold) MERGE

29 © 2007 by Prentice Hall4-29 4.20 Issuing MERGE to modify a table

30 © 2007 by Prentice Hall4-30 4.21 Illustration of transactions Time INSERT …DELETE …INSERT …UPDATE …COMMIT; INSERT … DROP TABLE… Transaction

31 © 2007 by Prentice Hall4-31 4.22 Using savepoints in a transaction creating a savepoint change rolled back to latest savepoint

32 © 2007 by Prentice Hall4-32 4.23 Modifying the Agents table

33 © 2007 by Prentice Hall4-33 4.24 Ending a transaction with COMMIT

34 © 2007 by Prentice Hall4-34 4.25 Creating a sequence and a BEFORE INSERT trigger

35 © 2007 by Prentice Hall4-35 4.26 Displaying Agents rows with trigger-supplied primary key values

36 © 2007 by Prentice Hall4-36 4.27 Creating an audit table and an AFTER UPDATE trigger

37 © 2007 by Prentice Hall4-37 4.28 Displaying the audit table

38 © 2007 by Prentice Hall4-38 4.29 A trigger execution error

39 © 2007 by Prentice Hall4-39 4.30 Correctly executing a statement-level trigger Output produced by statement-level trigger.

40 © 2007 by Prentice Hall4-40 4.31 Displaying trigger information


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

Similar presentations


Ads by Google