SQL Commands

You use the SQL commands to specify the tables and records you wish to extract or update. The main commands are:

Extract Records

SELECT <expression> FROM <table> WHERE <condition> GROUP BY <fields> HAVING <condition>
ORDER BY <fields>;

Update Records

DECLARE <name> CURSOR FOR <select statement>
FOR UPDATE OF <column names>;
UPDATE <table>;
DELETE FROM <table>;

Fetch the Next Record

FETCH FIRST/LAST/PRIOR/NEXT;

Insert a Record

INSERT INTO <table fields>;

Manage Updates

COMMIT WORK;
ROLLBACK WORK;

Date and Time

DATE(); TIME(); DAY(); MONTH(); YEAR(); HOUR(); MINUTE(); SECOND(); DAYS();

Below is an example SQL program excerpt to print out a list of the customers assigned to each employee by region:


select employee.employee_number,
employee.name,
customer.customer_number
customer.name
customer.address

from employee,
region,
customer

where employee.employee_number = region.employee_number
and region.region_code = customer.region_code

order by employee_number,
customer_number;