5.3 Lectures DML and DDL 2k24
5.3 Lectures DML and DDL 2k24
MSIT 2K24
Contents
2
Creating Data Storage Objects
3
Database Objects
Object Description
Table Basic unit of storage; composed of rows
and columns
• You specify:
• Table name
• Column name, column data type, and column size
Referencing Another User’s Tables
DESCRIBE dept
Tables in the Oracle Database
• User Tables:
• Are a collection of tables created and maintained by
the user
• Contain user information
• Data Dictionary:
• Is a collection of tables created and maintained by
the Oracle Server
• Contain database information
Querying the Data Dictionary
“Add a new
column to
the DEPT80
table.”
DEPT80
Adding a Column
• You use the ADD clause to add columns.
ALTER TABLE dept80
ADD (job_id VARCHAR2(9));
Table altered.
22
Data Manipulation Language
4 rows created.
UPDATE copy_emp
SET department_id = 110;
22 rows updated.
Problem
Update employee 114’s job and salary to match that of employee 205.
Updating Two Columns with a
Subquery
Update employee 114’s job and salary to match that of
employee 205.
UPDATE employees
SET job_id = (SELECT job_id
FROM employees
WHERE employee_id = 205),
salary = (SELECT salary
FROM employees
WHERE employee_id = 205)
WHERE employee_id = 114;
1 row updated.
Problem
Updates the COPY_EMP table based on the values from the EMPLOYEES table. It
changes the department number of all employees with employee 200’s job ID to
employee 100’s current department number.
Updating Rows Based
on Another Table
Use subqueries in UPDATE statements to update
rows in a table based on values from another table.
UPDATE copy_emp
SET department_id = (SELECT department_id
FROM employees
WHERE employee_id = 100)
WHERE job_id = (SELECT job_id
FROM employees
WHERE employee_id = 200);
1 row updated.
Updating Rows:
Integrity Constraint Error
UPDATE employees
SET department_id = 55
WHERE department_id = 110;
UPDATE employees
*
ERROR at line 1:
ORA-02291: integrity constraint (HR.EMP_DEPT_FK)
violated - parent key not found
Removing a Row from a Table
DEPARTMENTS