Академический Документы
Профессиональный Документы
Культура Документы
CREATE TABLE COMMAND Tables are defined with the CREATE TABLE
command. It is used to specify a new relation by giving its name and specifying its
attributes and initial constraints. When a table is created, its columns are named, data
types, sizes and any attribute constraints are supplied for each column. Each table must
have at least one column. The key, entity integrity, and referential integrity constraints
can be specified within the CREATE TABLE statement after the attributes are declared.
UNIQUE CONSTRAINT The constraint ensures that no two rows have the same
value in the specified column(s). For example, UNIQUE constraint can be applied as
1. At column level
2. At table level
UNIQUE constraint applied on ADNO of table STUREPT ensures that no rows have the
same ADNO value.
PRIMARY KEY CONSTRAINT This constraint declares a column as the primary
key of the table. This constraint is similar to unique constraint except that only one
column (or group of columns) can be applied in this constraint. The primary keys cannot
allow NULL values, thus, this constraint must be applied to columns declared as NOT
NULL. Consider the following example
1. At column level
2. At table level
PRIMARY KEY constraint applied on ADNO of table STUDATA ensures that no rows
have the same ADNO value and there are no NULL values.
DEFAULT CONSTRAINT A default value can be specified for a column using the
DEFAULT clause. When a user does not enter a value for the column (having the default
value), automatically the defined default value is inserted in the field. Consider the
following
According to the above command, the FNAME can never be NULL as the constraint
NOT NULL used.
FOREIGN KEY CONSTRAINT Foreign keys represent relationships between
tables. A foreign key is a column (or a group of columns) whose values are derived from
the primary key of the same or some other table. The existence of a foreign key implies
that the table with the foreign key is related to the primary key table from which the
foreign key is derived. A foreign key must have a corresponding primary key value in the
primary key table to have a meaning. Consider the following example
1. At column level
2. At Table Level