9-1 Copyright  Oracle Corporation, 1998. All rights reserved. Data Manipulation Language A DML statement is executed when you: – Add new rows to a table.

Slides:



Advertisements
Similar presentations
Data Definition Language (DDL)
Advertisements

Manipulating Data Schedule: Timing Topic 60 minutes Lecture
ORACLE TRANSACTIONS A transaction begins with the first executable SQL statement after a commit, rollback or connection made to the Oracle engine. All.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
Transaction Processing. Objectives After completing this lesson, you should be able to do the following: –Define transactions effectively for an application.
Introduction To SQL Lynnwood Brown President System Managers LLC Copyright System Managers LLC 2003 all rights reserved.
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
1 Data Concurrency David Konopnicki 1997 Revised by Mordo Shalom 2004.
8 Copyright © Oracle Corporation, All rights reserved. Manipulating Data.
Transaction Sen Zhang. Creating Transactions and Committing New Data Transaction: series of action queries that represent a logical unit of work User.
Copyright  Oracle Corporation, All rights reserved. 9 Manipulating Data: INSERT, UPDATE, DELETE.
At the end of this lesson, you should be able to: Describe each DML statement Insert rows into a table Update rows in a table Delete rows from a table.
Chapter 5 Data Manipulation and Transaction Control Oracle 10g: SQL
o At the end of this lesson, you will be able to:  Describe the life-cycle development phases  Discuss the theoretical and physical aspects of a relational.
Chapter 5 Data Manipulation and Transaction Control
4-1 Copyright  Oracle Corporation, All rights reserved. Data Manipulation Language (DML)
Copyright © 2011 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are trademarks of Accenture. SQL Workshop Day 3.
Program with PL/SQL. Interacting with the Oracle Server.
ACTION QUERIES (SQL COMMANDS ) STRUCTURED QUERY LANGUAGE.
SQL FUNDAMENTALS SQL ( Structured Query Language )
9 Copyright © 2007, Oracle. All rights reserved. Managing Data and Concurrency.
10 Creating and Managing Tables Objectives At the end of this lesson, you will be able to: Describe the main database objects Create tables Describe.
Objectives After completing this lesson, you should be able to do the following: Describe each data manipulation language (DML) statement Insert rows.
10-1 Copyright  Oracle Corporation, All rights reserved. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
Session 2: SQL (A): Parts 1 and 2 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram.
Database structure and space Management. Database Structure An ORACLE database has both a physical and logical structure. By separating physical and logical.
Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents.
Copyright  Oracle Corporation, All rights reserved. 18 Interacting with the Oracle Server.
8 Copyright © Oracle Corporation, All rights reserved. Manipulating Data.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Copyright  Oracle Corporation, All rights reserved. Introduction.
Copyright  Oracle Corporation, All rights reserved. 4 Introduction.
SQL: Part 1 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram. Not for commercial.
Manipulating Data. Objectives After completing this lesson, you should be able to do the following: Describe each DML statement Insert rows into a table.
9 Manipulating Data. 9-2 Objectives At the end of this lesson, you should be able to: Describe each DML statement Insert rows into a table Update rows.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
Database Programming Sections 14– database transactions and controlling User Access.
Enhanced Guide to Oracle 10g Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
Creating and Managing Tables 14. ObjectivesObjectives After completing this lesson, you should be able to do the following: After completing this lesson,
©Bob Godfrey, 2002, 2005 Lecture 17: Transaction Integrity and Concurrency BSA206 Database Management Systems.
10 1 Chapter 10 - A Transaction Management Database Systems: Design, Implementation, and Management, Rob and Coronel.
Oracle 10g Database Administrator: Implementation and Administration Chapter 10 Basic Data Management.
CSCI N311: Oracle Database Programming 5-1 Chapter 15: Changing Data: insert, update, delete Insert Rollback Commit Update Delete Insert Statement –Allows.
Copyright © 2004, Oracle. All rights reserved. M ANIPULATING D ATA.
SQL Statements SELECT INSERTUPDATEDELETECREATEALTERDROPRENAMETRUNCATECOMMITROLLBACKSAVEPOINTGRANTREVOKE Data Retrieval Language (DRL) Data Retrieval Language.
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
Insert, update, delete TCL. Data Manipulation Language – A DML statement is executed when you: Add new rows to a table Modify existing rows in a table.
Enhanced Guide to Oracle 10g
九.操作数据-DML语句 Schedule: Timing Topic 40 minutes Lecture
Manipulating Data Schedule: Timing Topic 60 minutes Lecture
Interacting with the Oracle8 Server
Interacting with the Oracle Server
Database structure and space Management
Manipulating Data.
Manipulating Data.
Manipulating Data Schedule: Timing Topic 60 minutes Lecture
Introduction to Oracle9i: SQL
Manipulating Data Schedule: Timing Topic 40 minutes Lecture
Manipulating Data.
Interacting with the Oracle Server
DATABASE MANAGEMENT SYSTEM
Manipulating Data.
处理数据 Schedule: Timing Topic 60 minutes Lecture 30 minutes Practice
(SQL) Manipulating Data
Manipulating Data.
Manipulating Data.
1 Manipulating Data. 2 Objectives After completing this lesson, you should be able to do the following:  Describe each data manipulation language (DML)
Manipulating Data Schedule: Timing Topic 40 minutes Lecture
DATABASE ADMINISTRATION
Presentation transcript:

9-1 Copyright  Oracle Corporation, All rights reserved. Data Manipulation Language A DML statement is executed when you: – Add new rows to a table – Modify existing rows in a table – Remove existing rows from a table A transaction consists of a collection of DML statements that form a logical unit of work. A DML statement is executed when you: – Add new rows to a table – Modify existing rows in a table – Remove existing rows from a table A transaction consists of a collection of DML statements that form a logical unit of work.

9-2 Copyright  Oracle Corporation, All rights reserved. The INSERT Statement Add new rows to a table by using the INSERT statement. Only one row is inserted at a time with this syntax. Add new rows to a table by using the INSERT statement. Only one row is inserted at a time with this syntax. INSERT INTOtable [(column [, column...])] VALUES(value [, value...]); INSERT INTOtable [(column [, column...])] VALUES(value [, value...]);

9-3 Copyright  Oracle Corporation, All rights reserved. Inserting Special Values The SYSDATE function records the current date and time. SQL> INSERT INTOemp (empno, ename, job, 2mgr, hiredate, sal, comm, 3deptno) 4 VALUES(7196, 'GREEN', 'SALESMAN', 57782, SYSDATE, 2000, NULL, 610); 1 row created.

9-4 Copyright  Oracle Corporation, All rights reserved. Inserting Specific Date Values Add a new employee. SQL> INSERT INTO emp 2 VALUES (2296,'AROMANO','SALESMAN',7782, 3 TO_DATE('FEB 3, 97', 'MON DD, YY'), , NULL, 10); 1 row created. Verify your addition. EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO AROMANO SALESMAN FEB

9-5 Copyright  Oracle Corporation, All rights reserved. Inserting Values by Using Substitution Variables Create an interactive script by using SQL*Plus substitution parameters. SQL> INSERT INTOdept (deptno, dname, loc) 2 VALUES (&department_id, 3 '&department_name', '&location'); 80 Enter value for department_id: 80 EDUCATION Enter value for department_name: EDUCATION ATLANTA Enter value for location: ATLANTA 1 row created.

9-6 Copyright  Oracle Corporation, All rights reserved. Updating Rows in a Table Specific row or rows are modified when you specify the WHERE clause. All rows in the table are modified if you omit the WHERE clause. Specific row or rows are modified when you specify the WHERE clause. All rows in the table are modified if you omit the WHERE clause. SQL> UPDATE emp 2 SET deptno = 20 3 WHERE empno = 7782; 1 row updated. SQL> UPDATE employee 2 SET deptno = 20; 14 rows updated. SQL> UPDATE employee 2 SET deptno = 20; 14 rows updated.

9-7 Copyright  Oracle Corporation, All rights reserved. Specific rows are deleted when you specify the WHERE clause. All rows in the table are deleted if you omit the WHERE clause. Specific rows are deleted when you specify the WHERE clause. All rows in the table are deleted if you omit the WHERE clause. Deleting Rows from a Table SQL> DELETE FROMdepartment 2 WHERE dname = 'DEVELOPMENT'; 1 row deleted. SQL> DELETE FROMdepartment 2 WHERE dname = 'DEVELOPMENT'; 1 row deleted. SQL> DELETE FROMdepartment; 4 rows deleted. SQL> DELETE FROMdepartment; 4 rows deleted.

9-8 Copyright  Oracle Corporation, All rights reserved. Database Transactions Consist of one of the following statements: DML statements that make up one consistent change to the data One DDL statement One DCL statement Consist of one of the following statements: DML statements that make up one consistent change to the data One DDL statement One DCL statement

9-9 Copyright  Oracle Corporation, All rights reserved. Database Transactions Begin when the first executable SQL statement is executed End with one of the following events: – COMMIT or ROLLBACK is issued – DDL or DCL statement executes (automatic commit) – User exits – System crashes Begin when the first executable SQL statement is executed End with one of the following events: – COMMIT or ROLLBACK is issued – DDL or DCL statement executes (automatic commit) – User exits – System crashes

9-10 Copyright  Oracle Corporation, All rights reserved. DELETE Controlling Transactions TransactionTransaction Savepoint A ROLLBACK to Savepoint B DELETE Savepoint B COMMIT INSERT UPDATE ROLLBACK to Savepoint A INSERTUPDATE INSERT ROLLBACK INSERT

9-11 Copyright  Oracle Corporation, All rights reserved. An automatic commit occurs under the following circumstances: – DDL statement is issued – DCL statement is issued – Normal exit from SQL*Plus, without explicitly issuing COMMIT or ROLLBACK An automatic rollback occurs under an abnormal termination of SQL*Plus or a system failure. An automatic commit occurs under the following circumstances: – DDL statement is issued – DCL statement is issued – Normal exit from SQL*Plus, without explicitly issuing COMMIT or ROLLBACK An automatic rollback occurs under an abnormal termination of SQL*Plus or a system failure. Implicit Transaction Processing

9-12 Copyright  Oracle Corporation, All rights reserved. State of the Data Before COMMIT or ROLLBACK The previous state of the data can be recovered. The current user can review the results of the DML operations by using the SELECT statement. Other users cannot view the results of the DML statements by the current user. The affected rows are locked; other users cannot change the data within the affected rows. The previous state of the data can be recovered. The current user can review the results of the DML operations by using the SELECT statement. Other users cannot view the results of the DML statements by the current user. The affected rows are locked; other users cannot change the data within the affected rows.

9-13 Copyright  Oracle Corporation, All rights reserved. State of the Data After COMMIT Data changes are made permanent in the database. The previous state of the data is permanently lost. All users can view the results. Locks on the affected rows are released; those rows are available for other users to manipulate. All savepoints are erased. Data changes are made permanent in the database. The previous state of the data is permanently lost. All users can view the results. Locks on the affected rows are released; those rows are available for other users to manipulate. All savepoints are erased.

9-14 Copyright  Oracle Corporation, All rights reserved. Committing Data SQL> UPDATEemp 2 SET deptno = 10 3 WHEREempno = 7782; 1 row updated. SQL> UPDATEemp 2 SET deptno = 10 3 WHEREempno = 7782; 1 row updated. Make the changes. Commit the changes. SQL> COMMIT; Commit complete.

9-15 Copyright  Oracle Corporation, All rights reserved. State of the Data After ROLLBACK Discard all pending changes by using the ROLLBACK statement. Data changes are undone. Previous state of the data is restored. Locks on the affected rows are released. Discard all pending changes by using the ROLLBACK statement. Data changes are undone. Previous state of the data is restored. Locks on the affected rows are released. SQL> DELETE FROMemployee; 14 rows deleted. SQL> ROLLBACK; Rollback complete.

9-16 Copyright  Oracle Corporation, All rights reserved. Rolling Back Changes to a Marker Create a marker in a current transaction by using the SAVEPOINT statement. Roll back to that marker by using the ROLLBACK TO SAVEPOINT statement. Create a marker in a current transaction by using the SAVEPOINT statement. Roll back to that marker by using the ROLLBACK TO SAVEPOINT statement. SQL> UPDATE... SQL> SAVEPOINT update_done; Savepoint created. SQL> INSERT... SQL> ROLLBACK TO update_done; Rollback complete.

9-17 Copyright  Oracle Corporation, All rights reserved. Statement-Level Rollback If a single DML statement fails during execution, only that statement is rolled back. The Oracle Server implements an implicit savepoint. All other changes are retained. The user should terminate transactions explicitly by executing a COMMIT or ROLLBACK statement. If a single DML statement fails during execution, only that statement is rolled back. The Oracle Server implements an implicit savepoint. All other changes are retained. The user should terminate transactions explicitly by executing a COMMIT or ROLLBACK statement.

9-18 Copyright  Oracle Corporation, All rights reserved. Read Consistency Read consistency guarantees a consistent view of the data at all times. Changes made by one user do not conflict with changes made by another user. Read consistency ensures that on the same data: – Readers do not wait for writers – Writers do not wait for readers Read consistency guarantees a consistent view of the data at all times. Changes made by one user do not conflict with changes made by another user. Read consistency ensures that on the same data: – Readers do not wait for writers – Writers do not wait for readers

9-19 Copyright  Oracle Corporation, All rights reserved. Locking Oracle locks: Prevent destructive interaction between concurrent transactions Require no user action Automatically use the lowest level of restrictiveness Are held for the duration of the transaction Have two basic modes: – Exclusive – Share Oracle locks: Prevent destructive interaction between concurrent transactions Require no user action Automatically use the lowest level of restrictiveness Are held for the duration of the transaction Have two basic modes: – Exclusive – Share