Professional Documents
Culture Documents
SID 205-2016
Manipulating Data
Course objectives
By completing this course, you will be able to:
Course topics
Course’s plan:
INSERT Statement
UPDATE Statement and
DEFAULT
DELETE Statement and
TRUNCATE
MERGE Statement
Transactions Control
Manipulating Data
INSERT Statement
INSERT Statement
New row
DEPARTMENTS
1 row created.
Creating a Script
Creating a Script
1 row created.
INSERT Statement
Part 1 Stop-and-think
EMPLOYEES
All rows in the table are modified if you omit the WHERE
clause:
UPDATE copy_emp
SET department_id = 110;
22 row updated.
UPDATE Statement and DEFAULT
Part 2 Stop-and-think
DEPARTMENTS
DELETE Statement
All rows in the table are deleted if you omit the WHERE
clause:
DELETE FROM copy_emp;
22 rows deleted.
DELETE Statement and TRUNCATE
TRUNCATE Statement
Example:
TRUNCATE TABLE copy_emp;
DELETE Statement and TRUNCATE
Part 3 Stop-and-think
MERGE Statement
MERGE Statement
MERGE Statement
MERGE Statement
The MERGE statement will allow to INSERT or UPDATE
into a table on a condition.
Merging lines
Insert or update rows in the COPY_EMP table to match
the EMPLOYEE table:
Merging lines
SQL> SELECT *
2 FROM COPY_EMP;
no rows selected
SELECT *
FROM COPY_EMP;
20 rows selected.
MERGE Statement
Part 4 Stop-and-think
Control Transactions
Transaction
ACID property
Atomic
Consistency
Isolation
Durability
Control Transactions
DELETE
SAVEPOINT A
INSERT
UPDATE
SAVEPOINT B
INSERT
ROLLBACK to ROLLBACK to ROLLBACK
SAVEPOINT B SAVEPOINT A
Control Transactions
UPDATE...
SAVEPOINT update_done ;
Savepoint created.
INSERT...
ROLLBACK TO update_done ;
Rollback complete.
Control Transactions
ROLLBACK ;
Rollback complete.
Control Transactions
ROLLBACK;
Rollback complete.
COMMIT;
Commit complete.
Control Transactions
Isolation
Read Consistency
database users access the database in two ways:
• Read operations (SELECT statement)
• Write operations (INSERT, UPDATE, DELETE statements)
You the following purpose :
• The database reader and writer are ensured a consistent view of
the data.
• Readers do not view data that is in the process of being changed.
• Writers are ensured that the changes to the database are done in a
consistent way.
• Changes made by one writer do not disturb or conflict with changes
that another writer is making.
Part 5 Stop-and-think
Summary
INSERT
DELETE
UPDATE DEFAULT
COMMIT and
Read-
ROLLBACK
TRUNCATE concistency