Java Reference
In-Depth Information
ssn
courseId
dateRegistered grade
Enrollment Table
444111110
11111
2004-03-19
A
444111110
11112
2004-03-19
B
444111110
11113
2004-03-19
C
...
courseId
Each value in
in the
Enrollment table must match a value
in
courseId
in the Course table
courseId subjectId
courseNumber
title
numOfCredits
Course Table
11111
CSCI
1301
Introduction to Java I
4
11112
CSCI
1302
Introduction to Java II
3
11113
CSCI
3720
Database Systems
3
...
Each row must have a
value for
Each value in the
numOfCredits
courseId
, and
the value must be unique
column must be
greater than 0 and less than 5
F IGURE 32.6
The Enrollment table and the Course table have integrity constraints.
Domain Constraints
Domain constraints specify the permissible values for an attribute. Domains can be specified
using standard data types, such as integers, floating-point numbers, fixed-length strings, and
variant-length strings. The standard data type specifies a broad range of values. Additional
constraints can be specified to narrow the ranges. For example, you can specify that the
numOfCredits attribute (in the Course table) must be greater than 0 and less than 5. You
can also specify whether an attribute can be null , which is a special value in a database
meaning unknown or not applicable. As shown in the Student table, birthDate may be
null .
Primary Key Constraints
To understand primary keys , it is helpful to know superkeys, keys, and candidate keys. A
superkey is an attribute or a set of attributes that uniquely identifies the relation. That is, no
two tuples have the same values on a superkey. By definition, a relation consists of a set of
distinct tuples. The set of all attributes in the relation forms a superkey.
A key K is a minimal superkey, meaning that any proper subset of K is not a superkey. A
relation can have several keys. In this case, each of the keys is called a candidate key . The
primary key is one of the candidate keys designated by the database designer. The primary
key is often used to identify tuples in a relation. As shown in Figure 32.6, courseId is the
primary key in the Course table.
Foreign Key Constraints
In a relational database , data are related. Tuples in a relation are related, and tuples in dif-
ferent relations are related through their common attributes. Informally speaking, the com-
mon attributes are foreign keys. The foreign key constraints define the relationships among
relations.
Formally, a set of attributes FK is a foreign key in a relation R that references relation T if
it satisfies the following two rules:
domain constraint
superkey
candidate key
primary key
relational database
foreign key constraint
foreign key
The attributes in FK have the same domain as the primary key in T .
A nonnull value on FK in R must match a primary key value in T .
 
 
Search WWH ::




Custom Search