Вы находитесь на странице: 1из 22

The Relational Database

Model
Objectives
• How relational database model takes a logical view of
data
• Understand how the relational model’s basic
components are relations implemented through tables in
a relational DBMS
• How relations are organized in tables composed of rows
(tuples) and columns (attributes)
• Use relational database operators, the data dictionary,
and the system catalog
• How data redundancy is handled in the relational
database model
• Why indexing is important
2
A Logical View of Data
• Relational model
– Enables programmer to view data logically
rather than physically
• Table
– Has advantages of structural and data
independence
– Resembles a file from conceptual point of
view
– Easier to understand than its hierarchical
and network database predecessors
3
Tables and Their
Characteristics
• Table: two-dimensional structure
composed of rows and columns
• Contains group of related entities = an
entity set
– Terms entity set and table are often used
interchangeably

4
Tables and Their
Characteristics (continued)
• Table also called a relation because the
relational model’s creator, Codd, used the
term relation as a synonym for table
• Think of a table as a persistent relation:
– A relation whose contents can be
permanently saved for future use

5
Tables and Their
Characteristics (continued)

6
Tables and Their Characteristics
(continued)

7
Keys
• Consists of one or more attributes that
determine other attributes
• Primary key (PK) is an attribute (or a
combination of attributes) that uniquely
identifies any given entity (row)
• Key’s role is based on determination
– If you know the value of attribute A, you
can look up (determine) the value of
attribute B
8
Keys
• A DBMS key is an attribute or set of an attribute which
helps you to identify a row(tuple) in a relation(table).
They allow you to find the relation between two tables.
Keys help you uniquely identify a row in a table by a
combination of one or more columns in that table.

9
Keys in Database Management System

• Super Key
• Primary Key
• Candidate Key
• Alternate Key
• Foreign Key
• Compound Key

10
What is the Super key?
A superkey is a group of single or multiple keys which identifies rows in a table.
A Super key may have additional attributes that are not needed for unique
identification.

11
What is a Primary Key?

• A column or group of columns in a table which helps us to uniquely


identifies every row in that table is called a primary key. This DBMS
can't be a duplicate. The same value can't appear more than once in
the table.

12
What is the Alternate key?

• All the keys which are not primary key are called an alternate key. It
is a candidate key which is currently not the primary key. However,
A table may have single or multiple choices for the primary key.

13
What is a Candidate Key?
A super key with no repeated attribute is called candidate key.
• It must contain unique values
• Candidate key may have multiple attributes
• Must not contain null values
• It should contain minimum fields to ensure uniqueness
• Uniquely identify each record in a table

14
What is the Foreign key?

15
What is the Compound key?
• Compound key has many fields which allow you to uniquely
recognize a specific record. It is possible that each column may be
not unique by itself within the database. However, when combined
with the other column or columns the combination of composite keys
become unique.

16
Constraints

17
Domain constraints
• Each table has certain set of columns and each column
allows a same type of data, based on its data type. The
column does not accept values of any other data type.
Domain constraints are user defined data type and
we can define them like this:

• Domain Constraint = data type + Constraints (NOT


NULL / UNIQUE / PRIMARY KEY / FOREIGN KEY /
CHECK / DEFAULT)

18
2. Tuple Uniqueness Constraint-
• Tuple Uniqueness constraint specifies that all the tuples must be
necessarily unique in any relation.

19
3. Key Constraint

• All the values of primary key must be unique.

• The value of primary key must not be null.

20
4. Entity Integrity Constraint-
• Entity integrity constraint specifies that no attribute of primary key
must contain a null value in any relation.
• This is because the presence of null value in the primary key
violates the uniqueness property.

21
5. Referential Integrity Constraint-
• This constraint is enforced when a foreign key references the
primary key of a relation.
• It specifies that all the values taken by the foreign key must either be
available in the relation of the primary key or be null.

22

Вам также может понравиться