Sie sind auf Seite 1von 5

Elements of the Database Approach

The Database Approach and the


Data Model
Lecture 2 AMV COMP3(Lec)

DATA MODELS
Graphical diagram capturing nature and relationship of data
Enterprise Data Modelhigh-level entities and relationships for
the organization
Project Data Modelmore detailed view, matching data structure
in database or data warehouse
ENTITIES
Noun form describing a person, place, object, event, or concept
Composed of attributes
RELATIONSHIPS
Between entities
Usually one-to-many (1:M) or many-to-many (M:N), but could
also be one-to-one (1:1)
RELATIONAL DATABASES
Database technology involving tables (relations) representing
entities and primary/foreign keys representing relationships

Figure 1: Comparison of enterprise and project level data models


Segment of an enterprise data model

Segment of a project-level data model

One customer
may place many
orders, but each
order is placed by
a single customer
One-to-many
relationship

One product can


be in many
order lines, each
order line refers
to a single
product
One-to-many
relationship

One order has many


order lines; each order
line is associated with
a single order
One-to-many
relationship

Therefore, one
order involves
many products
and one product is
involved in many
orders
Many-to-many
relationship

The Database Model


A Database Management System (DBMS) is a database manager,
which enables users to create and maintain databases.
The way data is actually stored in a database and managed by a
DBMS is defined by a database model.
Essentially, there are three types of database models: Relational,
Hierarchical and Network. Out of these, relational model is the
most widely used and is employed in most modern database products,
such as Oracle, MS Access, MySQL, MS SQL Server and DB2.

Relational Database

Relational Database
Relational database stores data in the form of tables
(also called a relation) with different tables linked to
each other via some data item.
Data can be accessed or reassembled from tables in
many ways without reorganizing the database tables.
Each table contains one or more data categories in
columns (also called fields).
Data values for every column are stored in rows, which
are also called tuples. Each tuple represent one record
value.

Relational Database

When creating a relational database, we can define a domain


of possible values in a data column and further constraints
that may apply to that data value. For example, one or more
fields can be assigned as index keys, which will speed up the
search process, when searching using the index.
In relational database one or more fields can also be assigned
as a key called primary key which ensures that only unique
values can be assigned in each row for that field(s).
Primary key is used to identify individual tuples in a relation. A
primary key cannot have null values. A relation can have more
than one key. In such case, each key is called as candidate
key and one of the candidate key is assigned as primary key.

The relational model dictates that each row in a table be unique. If


you allow duplicate rows in a table, then there's no way to uniquely
address a given row via programming. This creates all sorts of
ambiguities and problems that are best avoided. You guarantee
uniqueness for a table by designating a primary keya column that
contains unique values for a table.

Relational Database

CustomerId is a foreign key in tblOrder which can


be used to reference a customer stored in the
tblCustomer table. CustomerId is considered a
foreign key in tblOrder since it can be used to refer
to given customer

One-to-Many Relationships
Two tables are related in a one-to-many (1M) relationship if for every row in the
first table, there can be zero, one, or many rows in the second table, but for every
row in the second table there is exactly one row in the first table. For example,
each order for a pizza delivery business can have multiple items. Therefore,
tblOrder is related to tblOrderDetails in a one-to-many relationship. The one-tomany relationship is also referred to as a parent-child or master-detail
relationship. One-to-many relationships are the most commonly modeled
relationship.

One-to-many relationships are also used to link base tables to information stored in
lookup tables.

One-to-One Relationships

Two tables are related in a one-to-one (11) relationship if, for every
row in the first table, there is at most one row in the second table. True
one-to-one relationships seldom occur in the real world. The tables
tblPatient and tblConfidential are related in a one-to-one relationship.
The primary key of both tables is PatientId.
Tables that are related in a one-to-one relationship should always have
the same primary key, which will serve as the join column.

Many-to-Many Relationships
Two tables are related in a many-to-many (MM) relationship when for
every row in the first table, there can be many rows in the second table,
and for every row in the second table, there can be many rows in the first
table. Many-to-many relationships can't be directly modeled in relational
database programs,

A linking table, tblPtInsurancePgm, is used to model the many-to-many


relationship between tblPatient and tblInsurer.

The benefits of a database that has been designed according


to the relational model are numerous. Some of them are:

Data entry, updates and deletions will be efficient.


Data retrieval, summarization and reporting will also
be efficient.
Since the database follows a well-formulated model, it
behaves predictably.
Since much of the information is stored in the
database rather than in the application, the database
is somewhat self-documenting.
Changes to the database schema are easy to make.

Das könnte Ihnen auch gefallen