0% found this document useful (0 votes)
19 views18 pages

06.using DMLs

This document covers the Data Manipulation Language (DML) in Oracle SQL, detailing the syntax and examples for the Insert, Update, and Delete statements. It provides practical exercises for users to practice inserting, updating, and deleting records in database tables. Key concepts include the use of complete and incomplete rows for inserts, the importance of the WHERE clause in updates and deletes, and the use of sub-queries.

Uploaded by

ahmed elzoghby
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views18 pages

06.using DMLs

This document covers the Data Manipulation Language (DML) in Oracle SQL, detailing the syntax and examples for the Insert, Update, and Delete statements. It provides practical exercises for users to practice inserting, updating, and deleting records in database tables. Key concepts include the use of complete and incomplete rows for inserts, the importance of the WHERE clause in updates and deletes, and the use of sub-queries.

Uploaded by

ahmed elzoghby
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

CCIT : Database Design : Oracle SQL

06. Using DMLs


Eng:- Ahmed Ramadan , Eng:- Marwan Elkordey
Chapter 07 : Data Manipulation Language (DMLs)

Chapter Content :

- Insert Statement
- Update Statement
- Delete Statement
Chapter 07 : Data Manipulation Language (DMLs)

Insert Statement
syntax:
.......

insert into table_name (column_list)


values ( value_list );

Examples:
.........

1.1 ) complete row :


....................

insert into dept ( deptno , dname , loc )


values ( 22 , 'Acc' , 'Alex');

You will supply a value for each column


Chapter 07 : Data Manipulation Language (DMLs)

Insert Statement
With Complete Row its optional to write
column list

Insert into dept


values ( 61 , 'Customer Service' , 'Cairo' );
Chapter 07 : Data Manipulation Language (DMLs)

Insert Statement
With In-Complete Rows we have to write
column list

Example

Insert into dept ( deptno , dname )


values ( 62 , 'Payables' );
Chapter 07 : Data Manipulation Language (DMLs)

Insert Statement
Special Values

Example

insert into emp ( empno , ename , hiredate)


values ( 1111 , 'New Emp' , sysdate )
Chapter 07 : Data Manipulation Language (DMLs)

Update Statement

syntax :
........

update table_name
set column = value [ , column = value ] [ , column = value ]
[where condition ] ;
Chapter 07 : Data Manipulation Language (DMLs)

Update Statement
Examples :
----------
update emp set sal = 1000 ;

Without Where
All rows will be updated

Commit : to save changes


Rollback : cancel uncommitted changes
Chapter 07 : Data Manipulation Language (DMLs)

Update Statement
Example:
update emp set sal = 2000 where deptno = 20 ;

Only Rows of Deptno = 20


Will be updated
Chapter 07 : Data Manipulation Language (DMLs)

Update Statement
Example
update emp set sal = 3300 where empno = 7788 ;
Chapter 07 : Data Manipulation Language (DMLs)

Update Statement
Example
update emp set sal = 4000 , job='ANALYST' where empno = 7900 ;
Chapter 07 : Data Manipulation Language (DMLs)

Update Statement
Example
update emp
set sal = ( select sal from emp where empno=7788)
where empno = 7782 ;

Use Sub-Query to copy values from employee to another


Update clark salary with value =
the salary of the employee SCOTT
Chapter 07 : Data Manipulation Language (DMLs)

Delete Statement

syntax :
........
delete from table_name
[where condition ];

Examples
-------
delete from emp ; == delete emp ;
delete from emp where deptno = 10 ;
delete from emp where empno = 7788 ;
delete from emp where deptno = ( select deptno from emp
where ename='SCOTT' );
Chapter 07 : Data Manipulation Language (DMLs)

Delete Statement
Example
delete from emp ; == delete emp ;

All rows will be deleted

Use Rollback to get your rows again


Chapter 07 : Data Manipulation Language (DMLs)

Delete Statement
delete from emp where deptno = 10 ;
Chapter 07 : Data Manipulation Language (DMLs)

Delete Statement
delete from emp where empno = 7788 ;
Chapter 06 : Data Manipulation Language (DMLs)

Delete Statement
delete from emp where deptno = ( select deptno from emp where ename='SCOTT' );
Chapter 07 : Data Manipulation Language (DMLs)

Practices

1. Insert into dept table new department :with these Values deptno = 60 , dname = Inventory , dept Location = Alexandria
2. Insert into employee table new row with employee number = 1112 and employee name =‘New Emp’ , hiredate = today
3. Update emp table such that all employees in dept = 10 will have salary = 1000
4. Update emp table set the salary of employee no 7788 = the salary of employee no = 7782
5. Update emp set the min salaray in deptno 10 to be = min salary in deptno no 20
6. Update emp table set the salary of employee no = 7788 to be = 3000 and his job =‘Clerk’ and deptno=10 in one update ST.
7. Delete from emp table all employees work as analyst
8. Delete from emp all employees in the same department as employee scott
9. Delete from emp the employee who has minimum salary
10. Update emp set the job for the employee with maximum salary to be Salesman

You might also like