Entity Integrity

Entity Integrity
The primary key of a table must contain a unique, non-null value for each row. For example,
each row of the PropertyForRent table has a unique value for the property number propertyNo,
which uniquely identifies the property represented by that row. The ISO standard supports
entity integrity with the PRIMARY KEY clause in the CREATE and ALTER TABLE
statements. For example, to define the primary key of the PropertyForRent table, we include
the clause:
PRIMARY KEY(propertyNo)
To define a composite primary key, we specify multiple column names in the PRIMARY
KEY clause, separating each by a comma. For example, to define the primary key of the
Viewing table, which consists of the columns clientNo and propertyNo, we include the clause:
PRIMARY KEY(clientNo, propertyNo)
The PRIMARY KEY clause can be specified only once per table. However, it is still possible
to ensure uniqueness for any alternate keys in the table using the keyword UNIQUE. Every
column that appears in a UNIQUE clause must also be declared as NOT NULL. There may
be as many UNIQUE clauses per table as required. SQL rejects any INSERT or UPDATE
operation that attempts to create a duplicate value within each candidate key (that is, primary
key or alternate key). For example, with the Viewing table we could also have written:
clientNo VARCHAR(5) NOT NULL,
propertyNo VARCHAR(5) NOT NULL,
UNIQUE (clientNo, propertyNo)
Entity Integrity Entity Integrity Reviewed by Shopping Sale on 11:47 Rating: 5

No comments:

Powered by Blogger.