Will Contain All DML and DCL Statements
Will Contain All DML and DCL Statements
Will Contain All DML and DCL Statements
(value [, value...]);
departments (department_id,
department_name)
(30, 'Purchasing');
departments
(100, 'Finance', NULL, NULL);
Creating a Script
Use & substitution in a SQL statement to prompt for values.
& is a placeholder for the variable value.
INSERT INTO departments
(department_id, department_name, location_id)
VALUES
(&department_id, '&department_name',&location);
Copying Rows
from Another Table
Write your INSERT statement with a subquery:
INSERT INTO sales_reps(id, name, salary, commission_pct)
SELECT employee_id, last_name, salary, commission_pct
FROM
employees
WHERE job_id LIKE '%REP%';
UPDATE
SET
[WHERE
table
column = value [, column = value, ...]
condition];
Values for all the rows in the table are modified if you omit the
WHERE clause:
UPDATE
SET
copy_emp
department_id = 110;
WHERE
employees
job_id = (SELECT job_id
FROM
employees
WHERE
employee_id = 205),
salary = (SELECT salary
FROM
employees
WHERE
employee_id = 205)
employee_id
= 113;
copy_emp
department_id
WHERE
job_id
(SELECT department_id
FROM employees
WHERE employee_id = 100)
(SELECT job_id
FROM employees
WHERE employee_id = 200);
All rows in the table are deleted if you omit the WHERE clause:
DELETE FROM
copy_emp;
TRUNCATE Statement
Removes all rows from a table, leaving the table
empty and the table structure intact
Is a data definition language (DDL) statement rather
than a DML statement; cannot easily be undone
Syntax:
TRUNCATE TABLE table_name;
Example:
TRUNCATE TABLE copy_emp;
Database Transactions
A database transaction consists of one of the following:
DML statements that constitute one consistent change to
the data
One DDL statement
One data control language (DCL) statement
Advantages of COMMIT
and ROLLBACK Statements
With COMMIT and ROLLBACK statements, you
can:
Ensure data consistency
Preview data changes before making changes
permanent
Group logically-related operations
Time
UPDATE
SAVEPOINT B
INSERT
ROLLBACK
to SAVEPOINT B
ROLLBACK
to SAVEPOINT A
ROLLBACK