Sie sind auf Seite 1von 42

Components of a Database system

Database
Database Management Database
user
application System (DBMS)

•Create database
•Create and process forms
•Create tables
•Create and transmit queries
•Create supporting structures
•Create and process reports
•Read and update database
•Execute application logic
•Maintain db structures
•Control application
•Enforce rules
•Control concurrency
•Provide security
•Perform backup and recovery
What is Data Model
A set of concepts that can be used to describe
the structure of a database: the data types,
relationships, constraints, semantics and
operational behaviour.
or
A way of explaining the logical layout of the
data and the relationship of various parts to
each other and the whole
Types of data model
• Many models exist
– some are better suited for certain data
– some are easier for humans to work with
• Relational model
– easy enough for people to understand,
– easy for computer to manage efficiently
• The Entity Relationship Model
What is data abstraction?
• DBMS provides an abstract view of the
data to hide the complexity
Data Abstraction
View Level
View 1 View 2 …. View n
•Different users see different part of the database

Logical Level
•what data are stored & how they are related
•used by database administrators

Physical Level
•how the data are actually stored
•the concern of the database system
Abstraction Levels
Conceptual level (real word level, View
Level):
• The meaning of data
• How things are related
• What are rules in the real world that
should be respected in the database
Abstraction Levels
Structural level (logical level):
• How the programmer or the direct user of
the database sees the database
• Structures of data
• Operations on data
• Different users may have different views of
data
• Programming languages may also have
their own views of data
Abstraction Levels
Physical level:
• How is the data technically stored
• What kind of files distribution
• Structures to support fast retrieval of data
(indexes)
Illustration of Abstraction Levels
Entity relational model (ER)
• It is a logical db model, which has a logical
representation of data for an enterprise.
• It has become a widely accepted data
model.
• It is easily converted to other data models
• set of rules to transform to relational model
• easier for humans to work with
• graphical representation
Relational data model
• In 1970, Dr E.F.Codd described a new kind of
model Relational model where data are kept in
tables or relations.
Advantages:
• Simplicity
– It frees designer from the actual physical data storage details
• Structural independence
– Changes in the db structure do not affect the data access.
• Reduced retrieval time
• Interactive access more feasible
• DB2, Oracle, Informix, Sybase, MS SQL Server,
etc.
The Relational Model of Data
The basis :
• Database is considered as a collection of
relations (tables)
• Few simple and well defined concepts
• Good theoretical basis
• Easy to comprehend using tabular
representation
What is a Table?
• Tables are the core of your database, and
contain all the raw information. No other part
of the database can function without tables.
• Some databases store all the information in
one table. These are known as flat-file
databases.
• More commonly, databases store the
information in more than one table. These
are known as relational databases.
Relation presented as a table
Relation presented as table
Some definitions
Entity:
Any item about which information is stored.
e.g student, car, book etc
Entity set:
a collection of the entities of the same type.
e.g all students of an institute, employees of
a company.
In other words, a record describes the entity
and, a file describes an entity set.
More….
Attribute: Entity set Attributes
it is a property or
InventoryMod-no,
characteristic (field) of
name,
an entity
description,
e.g name, id no, salary unit price
• Values in all fields are
Employee Emp-no,
attributes. name,
fname,
salary
Relational Model Concepts
• The basic component of the relational model is a table
(or relation)
• Data in a database is represented as a collection of
table (each table has a unique name)
• Each table has a set of attributes (columns)
• Each column has a unique name.
• A row in a table represents a relationship among the
set of values (called a tuple or record) i.e a tuple
represents an instance of the entity set.
• All members of the entity set have the same attributes.
Theory – Tabular Presentation

,file,
entity set

, record

,field
Domain (of attribute):
The set of permitted values
– It is usually specified by name, data type, format &
constrained range of value
e.g in table Car, the mod-no attribute could only take
an integer value
key:
A key is one or more columns of a relation the is used to identify a row.
– a key can be unique or unique.

• Primary key: set of attributes uniquely


identifying records
• Foreign key: an attribute in a relation that is the
primary key from another relation
• in
Example of domain

Domain Registration Car color Model


Names number

Domain
values text text integer

Primary key
Table Design
• Each table, that might be used as a
master in a relationship with another table
(detail table), should have a field that is a
unique numeric identifier for each record. 
• There should be a unique field or
combination of fields (composite key) that,
when taken together, identify a unique
record in the table
Primary Key
• The records in a table are unique
• A record may be uniquely identified by its
contents
• Usually we don’t need the whole record for
the identification, only some attribute values
• A Primary key is an attribute (or attribute
combination) that has a unique value (or
value combination) in each row of a relation
Primary Key

• Reg_no and ModelYear both separately identify rows in this


instance
• ModelYear would not anyhow identify rows - that would mean that
there can be only one car for year model.
Primary Key –The Need
• Without a primary key you will get
duplicate records in your database and
this may cause your database to become
unusable
Rules for Primary Key
• Uniqueness
• Not Null - The field or fields that comprise a
primary key cannot be null.  This often
causes a problem when designing a table. 
In real life there are times when you just
don't know the value of a particular field
when you first enter data for a record in
your table. There are ways around this
problem
Primary Key vs Candidate Keys
• Sometimes we may find out many keys for a relation
schema
• Some of these keys must be selected as a primary key
Employee(personal_number,…, employee_number)
• Both employee_number and personal_number are keys
– we select as the primary the one that suits better for
the purpose. There are restrictions for the use of
personal number, thus employee number is a better
choice.
• Candidate keys provide a second route for getting to the
data in the table efficiently by using the index created
with this alternate key
Primary Key
• The primary key is expressed in the
relation schema by underlining its
attributes
• Car (RegNo, Color, ModelYear)
• Employee (EmployeeNumber,…)
• TennisCourtReservation (CourtID,
StartingTime, Duration, PlayerName1,
PlayerName2)
Foreign key

• A database consists of many table


• Typically there are connections between
records of different relations
• When you put a Unique identifier (PK)
from a master table into a subordinate
table then the ID field in the subordinate
table is called a 'foreign key' to the master
table.
Examples of Foreign Key
• A record in Employee relation is connected to a
record in Department relation indicating that the
employee works on that department
• A record in a library’s Loan relation is connected
to a record in relation Book and a record in
relation Customer.
• In relational databases records are connected by
including the primary key attribute values of the
record to be connected into the record that
establishes the connection.
Foreign Key
Foreign Key

• An attribute or a combination of attributes that


establishes a connection is called a foreign key.
• Connections are established using the values of
the primary key attributes of the record to be
connected as the values of the foreign key
attributes.
• Null values may be allowed for foreign keys –
then the records need not be connected to any
other records
Foreign Key
Foreign Key
• Foreign key values are
used in referring from one
record to another. However
the existence of the
connection may be utilized
also to the other direction
• Which department is
connected to a certain
employee
• Which employees are
connected to a certain
department
Foreign Key
• In this course we show the foreign keys using an arrow in the
following way

Ownership(PersonID Person, CarID Car)

• PersonID refers to Person, CarID refers to Car In this table the


foreign keys are part of the primary key. Thus they may not
have null values.
• Foreign keys may be outside the primary keys.
• Then they may or may not have null values

EMP(EmpNo, …, DeptNo DEPT)

• DeptNo refers to a record of DEPT


Foreign key
• Foreign keys may also be used in connecting records of
the same relation.
Employee(EmpNo, …,Boss Employee)
• attribute Boss has as its value the EmpNo value of some
other employee.
Referential integrity:
• It is not possible to refer to non-existing
records, i.e. the foreign keys may have as
their values only values that exist as
primary key values in their own relation.
• If NULL is used as the foreign key value
the record is not connected to anything.
Example
Foreign Key PrimaryKey Student
Enrolled table table

cid Grade stuid sid Nam Age gpa


MIS645 A 3456 e
CSC10 B 3466 3456 Ali 20 3.8
3 9876 Amy 19 3.4
CSC30 C 9876
5 2454 Sami 20 3.5
r
•MIS640 D as 55552354
Can we enter stuid
in Enrolled table 3466 Seha 19 3.2
•What should happen if we r
delete a tuple (sid=9876)
from students table 2345 Sam 20 3.0
Foreign Key – Graphical
Representation
Recap: Relational Database
Concepts
• The fundamental concept in relational systems is the
table.
• A database system that handles tables is not necessarily
a relational one.
• There are a number of rules that must be satisfied if the
database system is to qualify as relational.
• These rules are derived from the underlying mathematics
that provides a sound theoretical foundation.
• This gives practical benefits in areas like integrity and
recovery.
Steps in database development
• Requirements
– Determine application(s) requirements
– Build data model
• Design
– Tables
– Relationships
– Indexes
– Others structures
• Implementation
– Create database
– Create tables and relationships
– Create other structures
– Populate with data
– Build applications and test

Das könnte Ihnen auch gefallen