 |
|
What is SQL?
Oracle Tips by
Burleson
|
Structured Query Language (SQL) is a relatively young language
compared to languages like COBOL and Fortran, and it’s quite different
from those early ancestors.
SQL is a fourth-generation programming language (4GL), which means
that it allows the user to describe the data he or she wants without
giving precise instructions to the computer about how to retrieve the
data. This was a remarkable idea when SQL was first introduced, and
SQL remains the only 4GL in widespread use today. All of the major
relational database systems use SQL for accessing data (although all
of them, like Oracle’s SQL*Plus, include proprietary modifications to
the language).
SQL statements come in two varieties: data definition language and
data manipulation language.
Data Definition
Language
Data definition language (DDL) is language that defines how
data is stored within the relational database. A simple example of a
DDL statement is shown in Listing 2.5.
Listing 2.5 A simple DDL statement.
CREATE TABLE STUDENTS AS
(ssn NOT NULL number(9),
first_name NOT NULL varchar2 (10),
last_name NOT NULL varchar2 (12),
middle_name varchar2 (10),
street_address NOT NULL varchar2 (30),
apartment_number varchar2 (4),
city NOT NULL varchar2 (30),
state NOT NULL varchar2 (2),
zip_code NOT NULL number (5),
home_phone NOT NULL number (10));
This statement creates a table within the Oracle database to hold
information about students. Obviously, this is a very simple example.
As you become a more advanced developer, you’ll learn more about DDL.
Data Manipulation
Language
Data manipulation language (DML) is the most common type of
SQL that you’ll encounter. In case you haven’t already figured it out
by reading the name, this is the SQL that creates, deletes, reads, and
modifies data. Listing 2.6 displays a simple DML statement.
Listing 2.6 A simple DML statement.
SELECT last_name || ', ' || first_name || ' ' || middle_name
FROM STUDENTS
WHERE ssn = 999999999;
This statement returns the name of the student whose social
security number is 999-99-9999 from the STUDENTS table, in the
format “Doe, John Adam”. In addition to querying data from tables
using the SELECT statement, you can add data to tables with the
INSERT statement, modify the data in tables with the UPDATE
statement, and remove data from tables with the DELETE
statement.
This is an
excerpt from the book "High Performance Oracle Database
Automation" by Jonathan Ingram and Donald K. Burleson, Series
Editor. |