|
Structured Query Language (SQL), is used by most relational
database systems. Relational databases are databases that have
records that correspond to each other. A typical use of SQL in
Microsoft environments is in querying database tables created with
Access or Visual Basic. A typical use of SQL in Unix environments
might involve PERL/CGI.
Keywords:
| SELECT
- select/retrieve fields from 1 or more tables |
ORDER
BY - criteria for ordering/sorting records |
| FROM
- tables from which to get fields |
INSERT
INTO - insert values into 1 or more tables |
| WHERE
- criteria for rows to be retreived |
UPDATE
- update existing data in specified table(s) |
| GROUP
BY - criteria for grouping |
DELETE
FROM - delete data from specified table |
| ASC
- order ascending |
DESC
- order descending |
| AND
- logical AND |
OR
- logical OR |
Example:
SELECT Employee ID, FirstName, LastName, SSN,
YearBorn, PayRate
FROM Employees
ORDER
BY LastName, FirstName, SSN
---------------------------------------------------------------------------------------------------------------------------------
SELECT Employee ID, FirstName, LastName, SSN,
PayRate
FROM
Employees
WHERE LastName
LIKE 'Germany'
ORDER BY
SSN DESC
---------------------------------------------------------------------------------------------------------------------------------
INSERT INTO
Employees(FirstName, LastName)
VALUES(Charles,
Germany)
---------------------------------------------------------------------------------------------------------------------------------
UPDATE Employees
SET SSN =
24698763955
WHERE
LastName = 'Germany" AND
FirstName = 'Charles' |
Multiple Tables use the dot operator to
specify/identify fields from each table:
SELECT FirstName, LastName, SSN, PayRate
FROM
Employees, Clients
WHERE Employees.LastName
= Clients.LastName
ORDER BY
LastName ASC |
We are saying: From 2 tables, "Employees" and
"Clients", select FirstName, LastName, SSN, and PayRate.
Where both
tables have the same last name, order by last name in ascending order.
|