Sunteți pe pagina 1din 28

RDBMS and TABLE

RELATIONSHIPS IN ACCESS

Relational Database

The Relational Model was developed in 1970 by


E.F. Codd
A relation is nothing but a table/entities that
consists of records/tuples (rows) and
fields/attributes (columns).
A Relational Database Management System
(RDBMS) is a piece of software that manages
groups of tables which are related to one another.
MS Access is an example of RDBMS.

Relational Database
Terminology
SQL/Access
Term

RDBMS Term

Description

Row

Tuple or record

A data set
representing a
single item

Column

Attribute or field

A labeled element of
a tuple, e.g.
"Address" or "Date
of birth or Name

Table

Relation or entity

A set of tuples
sharing the same
attributes;
A set of columns and
rows

Advantages of a RDBMS

All data is stored in the database


Data redundancy is reduced
Easier to maintain data integrity
Eliminates the dependence
between programs and data.

The database can operate as a stand


alone application.

Properties of a Relation/Table
1. A relation consists of a set of attributes with
unique names (i.e., attribute names cannot
repeat in the SAME table). It doesnt matter
in which order the attributes are listed.
2. The values of attributes fall into a known
domain or legal values. For example, the
number of students in a class cannot be -20
or 3.26; it has to be a positive integer.

Properties of a
Relation/Table
3. Each tuple (row) in the database is unique. That is,
records do not repeat.

To avoid records from repeating, we have what is


called "Primary Key ". Primary key can uniquely
determine a record.

The primary key cannot take NULL value (means a


record cannot exist without a unique identifier). For
example, Student_ID is the primary key for STUDENT
table. One cannot enter a students information
without his/her Student_ID into the STUDENT table.

Types of Relational Keys

Candidate Key
Alternate Key
Primary Key
Foreign Key

Types of Relational Keys

Candidate Keys
- A minimal set of attributes in a table

that uniquely
identifies a record. When there is more than one
attribute in the candidate key, it is called composite key.

Alternate Keys
- Any candidate key that is not selected to be a
primary key can be an alternate key.

Types of Relational Keys

Primary Key
- A candidate key that is chosen to represent a
record uniquely. That is, a table may consist of many
candidate keys, but ONLY ONE can be selected as a
primary key. Note that a primary key can have more
than one attribute.

Foreign Keys
- is a column or group of columns in a relational

database table that provides a link between data in


two tables.

Table Relationship

A Relationship - is how you tell the program that


a piece of information means the same thing in
more than one table.
Table relationships can be created between two
tables as long as they have a common attribute.
Relationships are created using a Primary Key
from one table and linking it to a related field in
another table (now called a Foreign Key).

Table Relationship

Primary keys are used to uniquely


identify a table while a foreign key
is used to link tables using one of
the primary keys.

Table Relationship

Types of Relationships between


Tables
1. One-to-one
Rarely used, a record in the primary table
corresponds to one and only one record in the
related table. (Rare because fields that would go
into the second table are usually just put into the
primary table itself.)
Sample use: some information about a record must
be confidential; the confidential information is put
in a table with a one-to-one relationship to the main
table, and access to the second table is restricted.

One-to-one

Types of Relationships between


Tables
2. One-to-many
Very common, one record in the primary table can
be linked to many records in the related table, but
each record in the related table can be linked to only
one in the primary table.
Examples: A mother can have many children, but
each child has only one mother; a salesman can
make many sales, but any given sale is credited to
only one salesman; a person can have many library
books checked out but each book can be checked
out by only one person (at a time).

One-to-many

Types of Relationships between


Tables
3. Many-to-many
Very common, when a single record in one table can relate
to many records in another, and a single record in that
second table can also relate to many records in the first.
Examples: one author can write many books, and one
book can have several authors; one student can take many
classes and one class will have many students; one order
can contain many items, and one item can appear in many
orders.
These relationships are not established directly; they must
be accomplished through a junction table like Grades
below.

Many-to-many

Enforce Referential Integrity

An orphan record is one that refers to


a nonexistent record in another table,
such as the orders placed by
nonexistent customers.

Enforce Referential Integrity

The purpose of using referential


integrity is to prevent orphan records
and to keep references synchronized so
that you don't have any records that
reference other records that no longer
exist.
You enforce referential integrity by
enabling it for a table relationship.

Enforce Referential Integrity

Once enforced, Access rejects any


operation that would violate referential
integrity for that table relationship.
Access rejects updates that change the
target of a reference, and also deletions
that remove the target of a reference.

After you have enforced referential


integrity, the following rules apply:

You cannot enter a value in the foreign key


field of a related table if that value doesn't
exist in the primary key field of the primary
table doing so creates orphan records.
You cannot delete a record from a primary
table if matching records exist in a related
table. For example, you cannot delete an
employee record from the Employees table if
there are orders assigned to that employee in
the Orders table.

After you have enforced referential


integrity, the following rules apply:

You cannot change a primary key value in the


primary table if doing so would create orphan
records. For example, you cannot change an
order number in the Orders table if there are
line items assigned to that Order in the Order
Details table.

Referential Integrity Options


Cascade Update Related Fields
- permits the change of the primary key
of the one table and modifies the
related records in the many table to
match (e.g. if a library patron loses her
card, any books she has checked out
can be switched to her new card
number.)

Referential Integrity
Cascade Delete Related Fields
- permits the deletion of a record in
the one table and deletes all
related records in the many table.

** These options are usually turned on


when needed and turned OFF the
rest of the time.

Edit a Relationship

In the Relationships window,


double click the relationship line to
reopen the Edit Relationships box.

Delete a Relationship

In the Relationships window, right


click the relationship line and
choose Delete from the pop-up
menu, or click Delete in the
keyboard.

Thank You
Prepared by: Prof. LRQ Natividad

S-ar putea să vă placă și