L2 Database Models

Download as pdf or txt
Download as pdf or txt
You are on page 1of 43

Database

Models/Organizations
Introduction
• A Database model defines the logical design and structure of a
database and defines how data will be stored, accessed and updated
in a database management system.
• Four main types of database organization:
• File Oriented approach
• Hierarchical
• Relational
• Object-oriented
File Oriented approach/ FILE-BASED SYSTEM :
• The traditional file-oriented approach to information processing has
for each application a separate master file and its own set of personal
files. In file-oriented approach the program dependent on the files
and files become dependents upon the programs
Disadvantages of file-oriented approach:
• Data redundancy and inconsistency: The same information may be written
in several files. This redundancy leads to higher storage and access cost.
• It may lead to data inconsistency that is the various copies of the same
data may no longer agree for example a changed customer address may be
reflected in single file but not elsewhere in the system.
• Difficulty in accessing data: The conventional file processing system do not
allow data to retrieved in a convenient and efficient manner according to
user choice.
• Data isolation: Because data are scattered in various file and files may be in
different formats with new application programs to retrieve the
appropriate data is difficult.
• Integrity Problems: Developers enforce data validation in the system by
adding appropriate code in the various application programs. However,
when new constraints are added, it is difficult to change the programs to
enforce them.
Disadvantages of file-oriented approach:
• Atomicity: It is difficult to ensure atomicity in a file processing system
when transaction failure occurs due to power failure, networking
problems etc. (atomicity: either all operations of the transaction are
reflected properly in the database or non-are)
• Concurrent access: In the file processing system, it is not possible to
access a same file for transaction at same time
• Security problems: There is no security provided in file processing
system to secure the data from unauthorized user access.
Hierarchical Model
• This database model organizes data into a tree-like-structure, with a
single root, to which all the other data is linked. The hierarchy starts
from the Root data, and expands like a tree, adding child nodes to the
parent nodes.
• In this model, a child node will only have a single parent node.
• This model efficiently describes many real-world relationships like
index of a book, recipes etc.
• In hierarchical model, data is organized into tree-like structure with
one-to-many relationship between two different types of data, for
example, one department can have many courses, many professors
and off-course many students.
Hierarchical Model Cont.
Network Model
• This is an extension of the Hierarchical model. In this model data is
organized more like a graph, and are allowed to have more than one
parent node.
• In this database model data is more related as more relationships are
established. Also, accessing the data is also easier and fast due to the
relation between data. This database model was used to map many-
to-many data relationships.
• This was the most widely used database model, before Relational
Model was introduced.
Network Model Cont.
Relational Model
• In this model, data is organized in two-dimensional tables and the
relationship is maintained by storing a common field. i.e data is
organized in rows and columns.
• This model was introduced by E.F Codd in 1970, and since then it has
been the most widely used database model, in fact.
• The basic structure of data in the relational model is tables. All the
information related to a particular type is stored in rows of that table.
• Hence, tables are also known as relations in relational model. Primary
keys and foreign keys are used to show the relationships in relational
database models.
Relational Model Cont.
• The relational model provided a standard way of representing and querying
data that could be used by any application. From the beginning, developers
recognized that the chief strength of the relational database model was in
its use of tables, which were an intuitive, efficient, and flexible way to store
and access structured information.
• Over time, another strength of the relational model emerged as developers
began to use structured query language (SQL) to write and query data in a
database. For many years, SQL has been widely used as the language for
database queries.
• There are quite a number of tasks that can be conducted in relational
database models which include; Normalization, Querying using Structured
Query Language, etc
Relational Model Cont.
Keys in a database
Primary key
• A primary is a single column value used to identify a database record
uniquely.
• It has following attributes
• A primary key cannot be NULL
• A primary key value must be unique
• The primary key values should rarely be changed
• The primary key must be given a value when a new record is inserted.
Cont.
Composite Key
• A composite key is a primary key composed of multiple columns used to identify a record
uniquely
• In our database, we have two people with the same name Robert Phil, but they live in different
places. Hence, we require both Full Name and Address to identify a record uniquely. That is a
composite key.
Cont.
Foreign Key
• references the primary key of another Table! It helps connect your Tables
• A foreign key can have a different name from its primary key
• It ensures rows in one table have corresponding rows in another
• Unlike the Primary key, they do not have to be unique. Most often they
aren't
• Foreign keys can be null even though primary keys can not
• A foreign key references the primary key of the related table
• A foreign key can only have values present in the primary key of the related
table
• It could have a name other than that of the primary key of the related table
Cont.
• Candidate Key: A candidate key is a set of one or more columns that
could potentially serve as a primary key. From all the candidate keys,
one is selected as the primary key.
• Example for a student at MUT both the RegNo as well as national ID
number are unique identifiers so they both are candidate keys.
• Alternate key: An alternate key is any candidate key that is not the
primary key. Alternate keys can be used to create indexes on a table,
which can improve the performance of queries.
• Going by the example above, if RegNo is picked as primary key then
national ID becomes the alternate key
Cont.
• Surrogate Key: A surrogate key is an artificial primary key, often an
auto-incremented number, that is used as the primary key for a table.
It is not derived from the data itself but is generated solely for the
purpose of identifying records.
• Many DBMS will come with automatically autogenerated and
autoincrementing column named ID.
Relational Concepts
• Relational data model is the primary data model, which is used widely
around the world for data storage and processing.
• This model is simple and it has all the properties and capabilities
required to process data with storage efficiency.
Concepts
• Tables − A table has rows and columns, where rows represents
records and columns represent the attributes.
Cont.
• Tuple − A single row of a table, which contains a single record for that
relation is called a tuple.
• Entity- Database entity is a thing, person, place, unit, object or any
item about which the data should be captured and stored in the form
of properties, workflow and tables. Any real world entity
• Attribute: Characteristics of an entity, such as name, id etc. these
attributes constitute the tables in a relational database. It contains
the name of a column in a particular table.
Cont.
• Relationship- is a situation that exists between two relational
database tables when one table has a foreign key that references the
primary key of the other table. Types of Relationships
Cont.
There are three types of relationships in database design:
• One-to-One: A row in table A can have only one matching row in
table B, and vice versa.
• One-to-Many (or Many-to-One): A row in table A can have many
matching rows in table B, but a row in table B can have only one
matching row in table A.
• Many-to-Many: A row in table A can have many matching rows in
table B, and vice versa.
Cont.
What are the Benefits of Relationships?
Relationships are the basis of any relational database management
system (RDBMS). Relationships are a very powerful tool to use in
database design.
Here are some key benefits of relationships in database design:
• Reduces storage requirements
• Helps maintain data integrity (in particular, referential integrity)
• Helps increase usability for end users
• Easier data maintenance
• Helps with security
• Helps with scalability or expansion of the database
Cont.
• Relation instance − A finite set of tuples in the relational database
system represents relation instance. Relation instances do not have
duplicate tuples.
• Relation key − Each row has one or more attributes, known as
relation key, which can identify the row in the relation (table)
uniquely also known as foreign key.
• Domain: It contains a set of atomic values that an attribute can take.
• Data Types: Specific formats for storing data, such as VARCHAR for
text, INT for integers, and DATE for dates.
Cont.
• Relation schema − A relation schema describes the relation name
(table name), attributes, and their names.
• A database schema is a logical blueprint that defines the structure,
organization, and relationships of data stored in a database. It
provides a formal description of the database tables, columns, data
types, constraints, and relationships between tables.
• A well-designed schema ensures data integrity, efficient querying, and
ease of maintenance.
• Here's a simplified example of a database schema for a blog
application: check next page
Following Examples of Tables
• Users:
• user_id (Primary Key)
• username
• email
• password
• registration_date
• Posts:
• post_id (Primary Key)
• title
• content
• publish_date
• user_id (Foreign Key referencing Users table)
Example Cont.
• Comments:
• comment_id (Primary Key)
• text
• post_id (Foreign Key referencing Posts table)
• user_id (Foreign Key referencing Users table)
• comment_date
Cont.
• In this example, there are three tables: Users, Posts, and Comments.
Each table has its own set of columns, and relationships are
established between the tables using foreign keys. Here's a
breakdown of the schema elements:
• Primary Key: A unique identifier for each record in a table. It ensures
that each record is uniquely identifiable.
• Foreign Key: A column in one table that refers to the primary key in
another table. It establishes a relationship between tables.
• Columns: Fields that store different types of data, such as text,
numbers, dates, etc.
Cont.
Constraints
• Every relation has some conditions that must hold for it to be a valid
relation. These conditions are called Relational Integrity Constraints. There
are three main integrity constraints −
a) Key constraints
b) Domain constraints
c) Referential integrity constraints
• Key Constraints
• There must be at least one minimal subset of attributes in the relation,
which can identify a tuple uniquely. This minimal subset of attributes is
called key for that relation. If there are more than one such minimal
subsets, these are called candidate keys.
Cont.
• Key constraints force that −
a) in a relation with a key attribute, no two tuples can have identical values for key
attributes.
b) a key attribute cannot have NULL values.
• Key constraints are also referred to as Entity Constraints.
• Domain Constraints
• Attributes have specific values in real-world scenario. For example, age can
only be a positive integer. The same constraints have been tried to employ
on the attributes of a relation. Every attribute is bound to have a specific
range of values. For example, age cannot be less than zero and telephone
numbers cannot contain an alphabet character.
Cont.
• Referential integrity Constraints
• Referential integrity constraints work on the concept of Foreign Keys.
A foreign key is a key attribute of a relation that can be referred in
other relation.
• Referential integrity constraint states that if a relation refers to a key
attribute of a different or same relation, then that key element must
exist.
• Thus a foreign key cannot exist if a primary key in the related never
existed. Also, the foreign key must bear the same values as the
primary key in its related table.
The main Highlights of the relational database
model
• Data is stored in tables called relations.
• Relations can be normalized.
• In normalized relations, values saved are atomic values.
• Each row in relation contains unique value
• Each column in relation contains values from a same domain.
Object-Oriented Database Model
• The ODBMS is the data model in which data is stored in form of objects,
which are instances of classes. These classes and objects together make an
object-oriented data model.
• Components of Object-Oriented Data Model:
The OODBMS is based on three major components, namely: Object
structure, Object classes, and Object identity. These are explained as
following below.
• Object Structure: The structure of an object refers to the properties that
an object is made up of. These properties of an object are referred to as an
attribute.
• Thus, an object is a real-world entity with certain attributes that makes up the object
structure. Also, an object encapsulates the data code into a single unit which in turn
provides data abstraction by hiding the implementation details from the user.
Cont.

• Object Classes: An object which is a real-world entity is an instance


of a class. Hence first we need to define a class and then the objects
are made which differ in the values they store but share the same
class definition.
• The objects in turn corresponds to various messages and variables
stored in it.
• The Object-Oriented database model also implements object-
oriented programming concepts such as: Inheritance, Encapsulation,
polymorphism, and Abstraction.
• Object Identity: An object must have a unique name or identifier
Characteristics Object-Oriented Database
Model
• Easy to link with programming language: The programming language
and the database schema use the same type definitions, so
developers may not need to learn a new database query language.
• No need for user defined keys: Object Database Management
Systems have an automatically generated object identifiers (OID)
associated with each of the objects.
• Easy modeling: ODBMS can easily model real-world objects, hence,
are suitable for applications with complex data.
• Can store non-textual data ODBMS can also store audio, video and
image data.
Disadvantages Object-Oriented Database Model
• No universal standards: There is no universally agreed standards of
operating ODBMS This the most significant drawback as the user is free to
manipulate data model as he wants which can be an issue when handling
enormous amounts of data.
• No security features: Since use of ODBMS is very limited, there are not
adequate security features to store production-grade data.
• Exponential increase in complexity: ODBMS become very complex very
fast. When there is a lot of data and a lot of relations between data,
managing and optimizing ODBMS becomes difficult.
• Scalability: Unable to support large systems.
• Query optimization is challenging: Optimizing ODBMS queries requires
complete information about the data like-: type and size of data. This
compromises the data-encapsulation feature that ODBMS had to offer.
DBMS Functions
DBMS Functions
• Data Dictionary Management
• Data Dictionary is where the DBMS stores definitions of the data
elements and their relationships (metadata).
• The DBMS uses this function to look up the required data component
structures and relationships.
• When programs access data in a database they are basically going
through the DBMS. This function removes structural and data
dependency and provides the user with data abstraction.
• In turn, this makes things a lot easier on the end user. The Data
Dictionary is often hidden from the user and is used by Database
Administrators and Programmers.
DBMS Functions
• Data Storage Management: This particular function is used for the storage
of data and any related data entry forms or screen definitions, report
definitions, data validation rules, procedural code, and structures that can
handle video and picture formats.
• Users do not need to know how data is stored or manipulated. Also
involved with this structure is a term called performance tuning that
relates to a database‘s efficiency in relation to storage and access speed.
• Data Transformation and Presentation: This function exists to transform
any data entered into required data structures. By using the data
transformation and presentation function the DBMS can determine the
difference between logical and physical data formats.
DBMS Functions
• Security Management: This is one of the most important functions in
the DBMS. Security management sets rules that determine specific
users that are allowed to access the database.
• Users are given a username and password or sometimes through
biometric authentication (such as a fingerprint or retina scan) but
these types of authentication tend to be more costly. This function
also sets restraints on what specific data any user can see or manage.
• Multiuser Access Control: Data integrity and data consistency are the
basis of this function. Multiuser access control is a very useful tool in
a DBMS, it enables multiple users to access the database
simultaneously without affecting the integrity of the database.
DBMS Functions
• Backup and Recovery Management: Backup and recovery is brought
to mind whenever there is potential outside threats to a database.
For example if there is a power outage, recovery management is how
long it takes to recover the database after the outage.
• Backup management refers to the data safety and integrity; for
example backing up all your mp3 files on a disk.
• Data Integrity Management: The DBMS enforces these rules to
reduce things such as data redundancy, which is when data is stored
in more than one place unnecessarily, and maximizing data
consistency, making sure database is returning correct/same answer
each time for same question asked.
DBMS Functions
• Database Access Languages and Application Programming Interfaces: A
query language is a nonprocedural language. An example of this is SQL
(structured query language). SQL is the most common query language
supported by the majority of DBMS vendors.
• The use of this language makes it easy for user to specify what they want
done without the headache of explaining how to specifically do it.
• Database Communication Interfaces: This refers to how a DBMS can
accept different end user requests through different network
environments.
• An example of this can be easily related to the internet. A DBMS can
provide access to the database using the Internet through Web Browsers
(Mozilla Firefox, Internet Explorer, Netscape).
DBMS Functions
• Transaction Management: This refers to how a DBMS must supply a method that
will guarantee that all the updates in a given transaction are made or not made.
All transactions must follow what is called the ACID properties.
• A – Atomicity: states a transaction is an indivisible unit that is either performed
as a whole and not by its parts, or not performed at all. It is the responsibility of
recovery management to make sure this takes place.
• C – Consistency: A transaction must alter the database from one constant state
to another constant state.
• I – Isolation: Transactions must be executed independently of one another. Part
of a transaction in progress should not be able to be seen by another transaction.
• D – Durability: A successfully completed transaction is recorded permanently in
the database and must not be lost due to failures.
The End

Q & A Session

You might also like