Data Manipulation - PowerPoint PPT Presentation

About This Presentation
Title:

Data Manipulation

Description:

Chapter insert/manipulate data. Introduction to Oracle9i: SQL. 1. Data Manipulation ... Identify table in the INSERT INTO clause. Specify data in the VALUES clause ... – PowerPoint PPT presentation

Number of Views:115
Avg rating:3.0/5.0
Slides: 27
Provided by: lm585
Learn more at: https://www3.nd.edu
Category:

less

Transcript and Presenter's Notes

Title: Data Manipulation


1
Data Manipulation
2
Chapter Objectives
  • Add a record to an existing table
  • Add a record containing a NULL value to an
    existing table
  • Use a subquery to copy records from an existing
    table
  • Modify the existing rows within a table

3
Chapter Objectives
  • Use substitution variables with an UPDATE command
  • Issue the transaction control statements COMMIT
    and ROLLBACK
  • Differentiate between DDL, DML, and transaction
    control commands

4
Chapter Objectives
  • Delete records
  • Differentiate between a shared lock and an
    exclusive lock
  • Use the SELECTFOR UPDATE command to create a
    shared lock

5
INSERT Command
  • Used to add rows to existing tables
  • Identify table in the INSERT INTO clause
  • Specify data in the VALUES clause
  • Can only add one row at a time to a table

6
INSERT Command Syntax
  • Enclose non-numeric data in single quotes
  • If column list not provided, a value must be
    assigned to each column in the table

7
INSERT Command Example
8
Inserting NULL Value
  • Omit column name from INSERT INTO clause column
    list
  • Substitute two single quotation marks
  • Use NULL keyword

9
Inserting Data from an Existing Table
  • Substitute subquery for VALUES clause

10
Modifying Existing Rows
  • Modify rows using UPDATE command
  • Use UPDATE command to
  • Add values to an existing row
  • Change existing values

11
UPDATE Command
  • UPDATE clause identifies table
  • SET clause identifies column being changed and
    new value
  • Optional WHERE clause specifies row(s) to be
    changed if omitted, will update all rows

12
UPDATE Command Syntax
13
UPDATE Command Example
14
  • Note select query format is determined at the
    time of the select statement e.g.
  • Select title, to_char(pubdate, MONTH DD, YYYY)
    Publication Date,
  • to_char (retail, 999.99) Retail Price
  • from books

15
Substitution Variables
  • Prompts user for value
  • Identified by ampersand () preceding variable
    name
  • Can be used to create interactive scripts

16
Substitution Variable Example
17
Transaction Control
  • Results of Data Manipulation Language (DML) are
    not permanently updated to table until explicit
    or implicit COMMIT occurs
  • Transaction control statements can
  • Commit data through COMMIT command
  • Undo data changes through ROLLBACK command

18
COMMIT
  • Explicit COMMIT occurs by executing COMMIT
  • Implicit COMMIT occurs when DDL command is
    executed or user properly exits system
  • Permanently updates table(s) and allows other
    users to view changes

19
ROLLBACK
  • Used to undo changes that have not been
    committed
  • Occurs when
  • ROLLBACK is executed
  • System restarts after crash

20
Deleting Rows//
  • DELETE command removes a row from a table

21
DELETE Command Omitting WHERE Clause
  • Omitting WHERE clause removes all rows

22
Table Locks
  • Prevents users from changing same data or objects
  • Two types
  • Shared prevents DML operations on portion of
    table
  • Exclusive locks table preventing other
    exclusive or shared locks

23
Shared Lock
  • Locks portion of table affected by DML operation
  • Implicitly occurs during UPDATE or DELETE
    operations
  • Explicitly occurs through LOCK TABLE command with
    SHARE MODE option
  • Released when COMMIT (implicit or explicit) or
    ROLLBACK occurs

24
Exclusive Lock
  • Implicitly locks table for DDL operations -
    CREATE or ALTER TABLE
  • Explicitly locked through LOCK TABLE command with
    EXCLUSIVE MODE option
  • Released after execution of DDL operation or
    after user exits system

25
SELECTFOR UPDATE Command
  • Creates shared lock on retrieved portion of table
  • Prevents one user from changing a row while
    another user is selecting rows to be changed
  • Released through implicit or explicit commit

26
SELECTFOR UPDATE Command Example
Write a Comment
User Comments (0)
About PowerShow.com