Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
SQL is widely used as a relational database language, designated by ANSI and ISO as a standard Created by IBM SQL is a complete database language. It is used for Defining relational database Creating views and specifying queries In addition, it allows for rows to be inserted, updated and deleted
Indexes are used to accelerate data access and ensure uniqueness. An index may be thought of as a table that contains two columns
10
the second column contains a list of pointers or addresses of rows in the table
11
C
C
E E N N N C
C
C
E
E
F
N
7
8 9 10
C
C C F
White
green Black khaki
12
N
N
13
14
14
[referential-constraint-block] [unique-block]
18
The not null clause specifies that the particular column must have a value whenever a row is inserted.
NOT NULL should be defined for a column that is a primary key or a component of a primary key.
19
A table can have only one primary key, which may be a single key or a composite key
22
While it is not mandatory to define a primary key, it is good practice to always define a primary key for a table,
23
Structured Query Language (SQL) Referential Constraint Definition-1 The referential constraint block defines a foreign key.
It consists of one or more columns in the table that together must match a primary key (or else be null) of the specified table. A foreign key value is null when any one of the columns in the row comprising the foreign key is null
24
Once the foreign key is defined, the DBMS will check every insert and update to ensure that the constraint is observed
25
Column-name identifies the column or columns that comprise the foreign key. The data type and length of the foreign key must match exactly the data type and length of the primary key columns The clause REFERENCES table-name specifies the name of the existing table that contains the primary key, which cannot be the name of the table being created.
26
Unique Definition
The unique definition block creates a unique index for the specified column or columns A unique key is constrained so that no two of its values are equal Columns appearing in the unique constraint must be defined as NOT NULL Format:
UNIQUE constraint-name (Column-name [ASC/DESC][,])
Example: UNIQUE unqnatcode (natcode) DESC or UNIQUE (natcode)
28
The constraint is enforced by the DBMS during execution of the INSERT and UPDATE statements. The column-name clause identifies the column or columns that comprise the unique key. These columns should not be the same as those of the tables primary key definition.
The ASC/DESC option specify whether the columns of the unique key are arranged in ascending or descending order, respectively.
uc INTEGER (15),
stkfirm CHAR(20), stkprice DECIMAL (6,2), stkqty DECIMAL (8), stkdiv DECIMAL (5,2), stkpe DECIMAL(5), natcode CHAR(3), arrdateE DATE,