Java Reference
In-Depth Information
SQL statements may be divided into two broad categories:
Data Manipulation Language (DML) statements;
Data Defi nition Language (DDL) statements.
It is primarily the fi rst of these with which we shall be concerned, but each
will be covered below. Whether a DML statement or a DDL statement, every SQL
statement is terminated with a semi-colon. It is also conventional for the SQL
keywords to appear in upper case, attributes (fi elds) in lower case and table names
in lower case commencing with a capital letter.
A.1
DDL Statements
These are statements that affect the structure of a table by creating/deleting attri-
butes or whole tables. Since these activities are usually much more conveniently and
appropriately carried out via a GUI that is provided by the database vendor, not
much attention will be paid to these statements, but the syntax for each is shown
below, with examples relating to our Stock table.
A.1.1
Creating a Table
This is achieved via the CREATE TABLE statement. Syntax:
CREATE TABLE <TableName>(<fi eldName> <fi eldType>
{,<fi eldName> <fi eldType>});
For example:
CREATE TABLE Stock(stockCode INTEGER,
description VARCHAR(20),
unitPrice REAL,
currentLevel INTEGER,
reorderLevel INTEGER);
Just to complicate things, some databases would use FLOAT , DECIMAL
(<n>,<d>) or NUMERIC instead of REAL above. (The 'n' and 'd' refer to the
total number of fi gures and number of fi gures after the decimal point respectively.)
A.1.2
Deleting a Table
This is very straightforward via the DROP statement. Syntax:
DROP TABLE <TableName>;
Search WWH ::




Custom Search