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

Entity relation model

History of ER
- Peter Chan 1971
-
What is ER Diagrams?
- This model occurs with
visualisation of plan
- The diagram represents the
database and the relation
between the tables
- Each column will be represented
by a key
- These keys help connect tables.
The keys include
primary/foreign key, secondary
key
- We use the same symbols to
define each table/make them
unique
- all documents are shareable.
this helps with the team work
Why use ER Diagrams?
- A way to demonstrate data efficiently
- Easy and clear
- Shareable
- Can demonstrate relations between tables
- Easily modifiable
- Expandable
- Comprehensive
Components of the ER Diagram
- Entity
- Attribute
- Relation

- Entity can be only entity (no


weak)
Examples of entities
- Cars
- Students
- Hospital (staff)
- Vegetables
Entity set
- Is essentially a table with
connections.
Relationship
- There are two types of
relationships: optional and
partitional
- Optional relations include:
optional and mandatory
- Partitional include: one-to-
one, one-to-many, many-to-
many
Weak Entities
- This is a weak entity as
there is no primary key
Strong Entity Set vs. Weak Entity Set
- Has a primary key - No primary key

- Relations can be created - Weak relations


between entities - Bigger tables
- Creating smaller tables - Non hierarchal
(normalisation)
- Optional relations
- Hierarchy data set
- Dependency
- Partitional relations
- Independency -

-
Attributes
• Attributes can be defined my
symbol and context/content
Type of attributes
- string

- char

- int

- bool
Cardinality
- The four basic relations
demonstrated here are enough

- If a many-to-many relation is
created it’d create a weak entity
set

-
ER- Diagram Notations
- Strong entity: rectangle
- Weak entity: double
- Attributes: oval
- Relation: line with symbols
- Mandatory: small line
- optional: small circle
- one: small line
- Many: 3 lines
Steps to Create an ERD
1.
2.
3.
4.
5.
Developing Effective ER Diagrams
- Create strong entity sets
- Use easy-to-read naming and symbols
- Clear symbols
- Not to connect tables with same keys
-
-
-
Relational databases
Data and Database
•-
•-
•-
•-
•-
Data independences
• Type of data independences
• Physical
• Logical
Examples of changes under Physical Data
Independence
•-
•-
•-
•-
•-
•-
•-
Logical Data Independence
• External views
• External API or programs
Examples of changes under Logical Data
Independence
•-
•-
•-
Difference between Physical and Logical Data
Independence
• Logical data independence • Physical data independence
- -
- -
- -
- -
- -
- -
- -
Importance of Data Independence
-
-
-
-
-
-
-
-
Levels of Database
-
-
-
Type of schema
1.
2.
3.
Relation models
Relation model concepts
• 1. Attribute
• 2. Tables
• 3. Tuple
• 4. Relation Schema
• 5. Degree
• 6. Cardinality
• 7. Column
• 8. Relation instance
• 9. Relation key
• 10. Attribute domain
Relational Integrity constraints
1.
2.
3.
Operations in Relational Model
-
-
-
-
Advantages of using Relational model
•-
•-
•-
•-
•-
•-
Disadvantages of using Relational model
1.
2.
3.
Relational database systems.
The SQL language, DDL, DML,
DCL. Schema, relations and
relation operations in SQ
RDMS
• designed specifically for relational databases
• RDBMSes are a subset of DBMSes
Relational database
• Database
• Rows
• Columns
• Applications
Non-relational databases
• Apache Hbase
• IBM Domino
• Oracle NoSQL Database
SQL
• Structured Query Language
• MySQL
• MS Access
• Oracle
• Sybase
• Postgres
• SQL Server
Why Use SQL?
• It helps users to access data in the RDBMS system.
• It helps you to describe the data.
• It allows you to define the data in a database and manipulate that
specific data.
• With the help of SQL, you can create and drop databases and tables.
• SQL offers you to use the function in a database, create a view, and
stored procedure.
• You can set permissions on tables, procedures, and views.
Types of SQL

• Data Definition Language (DDL)


• Data Manipulation Language (DML)
• Data Control Language(DCL)
• Transaction Control Language(TCL)
• Data Query Language (DQL)
DDL
• CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[,....])
• DROP TABLE TABLE_NAME
• ALTER TABLE table_name ADD column_name COLUMN-definition
• TRUNCATE TABLE table_name
• Insert TABLE_NAME (col1, col2…) Values(value1, value2…)
• Update TABLE_NAME set column_name=new_value
• DELETE FROM table_name [WHERE condition]
DML
• INSERT

• UPDATE

• DELETE
DDL vs. DML
- The DML statements allow you to
• Allows you to store shared data
modify the data stored in a
• Data independence improved database.
integrity
- Users can specify what data is
• Allows multiple users needed.
• Improved security efficient data - DML offers many different flavors
access and capabilities between database
vendors.
- It offers an efficient human
interaction with the system
DCL
• GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER,
ANOTHER_USER

• REVOKE privilege_nameON object_nameFROM {user_name |PUBLIC


|role_name}
TCL
• Commit (commit;)
• Rollback (SAVEPOINT SAVEPOINT_NAME)
DQL
• Select (SELECT expressions FROM TABLES WHERE conditions)
DBMS Schemas
• Internal level
- The internal schema is the lowest level of data abstraction
- It helps you to keeps information about the actual representation of the entire database. Like the actual storage of the data on the disk in the form of records
- The internal view tells us what data is stored in the database and how
- It never deals with the physical devices. Instead, internal schema views a physical device as a collection of physical pages

• Conceptual or Logical Level


- Defines all database entities, their attributes, and their relationships
- Security and integrity information
- In the conceptual level, the data available to a user must be contained in or derivable from the physical level

• External or View level


- An external level is only related to the data which is viewed by specific end users.
- This level includes some external schemas.
- External schema level is nearest to the user
- The external schema describes the segment of the database which is needed for a certain user group and hides the
remaining details from the database from the specific user group
Goals
• Every user should be able to access the same data but able to see a
customized view of the data.
• The user need not to deal directly with physical database storage
detail.
• The DBA should be able to change the database storage structure
without disturbing the user's views
• The internal structure of the database should remain unaffected
when changes made to the physical aspects of storage
Open-sources DBMS
• 1. MySQL
Platform: Linux, Windows, and Mac.

Languages: C, Java, SQL, C++, Perl, Python, Tcl, and PHP.

Cloud Version: Yes


Open-sources DBMS
• 2. PostgreSQL
Platform: Mac, Windows, and Linux.
Languages: PL/Tcl, PL/pgSQL, PL/Python, and PL/Perl.
Cloud Version: No.
Open-sources DBMS
• 3. MongoDB
Platform: Cross-platform
Languages: C#, C, Java, C++, Perl, Scala, Ruby, etc.
Cloud Version: Yes
Open-sources DBMS
• 4. SQLite
Platform: Blackberry, Symbian, Maemo, Android, MeeGo,
WebOS, NetBSD, FreeBSD, illumos, Solaris 10, Windows, and
Tizen.
Languages: C, C#, C++, Java, PHP, Python, Ruby, etc.
Cloud Version: Yes
Open-sources DBMS
• 5. MSSQL
Platform: Docker Engine, Ubuntu, SUSE Linux Enterprise Server,
and Red Hat Enterprise Linux.
Languages: C, C++, Java, and C#
Cloud Version: Yes
Maintance
Maintance
- Offline
- Schedule tasks
- update
- Online
- MongoDB->Sync
Maintance
- Index recognize->reorganized
- Index rebuild
- update
- integrity
- repair
Maintance process

• upload, insert, DML


• Delete/Drop
• Structure modification
• Search, sort, filter, order
Maintance query
• When?
• Table create
• Update
• Join
• Delete
• XOR
Stock operations
• Open/import option
• Save modes (backup)
• Security functions
• Joins update
Normalization
Database Normal Forms
• 1NF (First Normal Form)
• 2NF (Second Normal Form)
• 3NF (Third Normal Form)
• BCNF (Boyce-Codd Normal Form)
• 4NF (Fourth Normal Form)
• 5NF (Fifth Normal Form)
• 6NF (Sixth Normal Form)
Database Normalization With Examples
Name Job title Date of Birth

Dr. Margit Pap Director 1955

Dr. Zoltan Horvath Professor assistant 1979


Erasmus coordinator
Dr. Norbert Zentai Lecturer 1982
1NF (First normal form)
Name Job title Date of birth
Dr. Margit Pap Director 1955
Dr. Zoltan Horvath Prof. Assistant 1979
Dr. Zoltan Horvath Erasmus coordinator 1979
Dr. Norbert Zentai Lecturer 1982

-
-
What is the key?
Primary key
-
-
-
-
-
-
What is the composite key?
2NF rules
ID Name DoB.
1 Dr. Margit Pap 1955
2 Dr. Zoltan Horvath 1979
2 Dr. Zoltan Horvath 1979
3 Dr. Norbert Zentai 1982

ID Job position
1 Director
2 Prof. assistant
2 Erasmus coordinator
• Rule 1- Be in 1NF 3 Lecturer
• Rule 2- Single Column Primary Key
Foreign Key
-
-
-
-
Foreign key
• Insert a record in Table B
ID Job Title
5 Visitor professor

But the ID 5 isn’t present Table A


ID Name DoB
1 Dr. Margit Pap
2 Dr. Zoltan Horvath
2 Dr. Zoltan Horvath
3 Dr. Norbert Zentai

Database will throw an Error. This help in referntial integrity.


Transitive functional dependencies
ID Name Job Title DoB
1 Dr. Margit Pap Director 1955
2 Dr. Zoltan Horvath Prof. Assistant 1979
3 Dr. Ildiko Jenak Prof. Assistant 1995

Consider the table 1. Changing the non-key column Name may change Date of Birth
3NF
ID Name Job title DoB
1 Dr. Margit pap Director 1955
2 Dr. Zoltan Horvath Prof. Assistant 1979
2 Dr. Zoltan Horvath Erasmus coordinator 1979

ID Job title ID DoB


1 Director 1 1955
2 Prof. Assistant 2 1979
2 Erasmus coordinator 2 1979
BCNF
• more than one Candidate Key
• 3.5NF
4-6NF
• 4NF (Fourth Normal Form) Rules
• If no database table instance contains two or more, independent and
multivalued data describing the relevant entity, then it is in 4th Normal
Form.
• 5NF (Fifth Normal Form) Rules
• A table is in 5th Normal Form only if it is in 4NF and it cannot be
decomposed into any number of smaller tables without loss of data.
• 6NF (Sixth Normal Form) Proposed
• 6th Normal Form is not standardized, yet however, it is being discussed by
database experts for some time. Hopefully, we would have a clear &
standardized definition for 6th Normal Form in the near future.
Example
Each table cell should contain a single value
Date Product Product Price Pieces
name code
88.02.03 Milk TX-5 1500 2
Coke XB-3 150 6
Beer ET-2 30 4
Wein F-6 120 1
SumValue: 4140
Payment: 3140
Example
Date product Product Price Pieces Sum Payment
name code value
88.02.03 Milk TX-5 1500 2 4140 3140
88.02.03 Coke XB-3 150 6 4140 3140
88.02.03 Beer ET-2 30 4 4140 3140
88.02.03 Wein F-6 120 1 4140 3140
88.02.04 Wein F-6 120 1 4620 3620
88.02.04 Milk TX-5 1500 3 4620 3620
88.02.05 Coke XB-3 150 2 3600 2600
88.02.05 Water P-12 1100 3 3600 2600
Key = {Date,productcode}

Product
Date
code

Pieces
Sumvalu Payment Productname Price
• Date Date Pcode
Pcode
• SumValue
Pname
• Payment Pieces Price

Daily income Sale Products


Daily income{Date,SumValue,Paid}

Which NF is this?
Date SumValue Payment
88.02.03 4140 3140
88.02.04 4620 3620
88.02.05 3600 2600
88.02.06 4620 3620
Date SumValue

SumValue Payment

Sales revenue Payment


SalesReveneu{Date,SumValue}
Date SumValue
88.02.03 4140
88.02.04 4620
88.02.05 3600
88.02.06 4620

Payment{SumValue,Payment}
SumValue Payment
4140 3140
4620 3620
3600 2600
Parts{Pcode,Pname,Price}

Pcode Pname Price


TX-5 KUPLUNG 1500
XB-3 ELOSZTÓFEJ 150
ET-2 KONDENZÁTOR 30
F-6 FÉKHENGER 120
P-12 VÍZPUMPA 1100
Sales{Date,Pcode,Pieces}

Date Pcode Pieces


88.02.03 TX-5 2
88.02.03 XB-3 6
88.02.03 ET-2 4
88.02.03 F-6 1
88.02.04 F-6 1
88.02.04 TX-5 3
88.02.05 XB-3 2
88.02.05 P-12 3
Transactions, transaction
handling. ACID properties.
Isolation. States of transactions.
Serializability
Transaction execute
Database Transactions
• A transaction is a program unit whose execution may or may not
change the contents of a database.
• The transaction concept in DBMS is executed as a single unit.
• If the database operations do not update the database but only
retrieve data, this type of transaction is called a read-only transaction.
• A successful transaction can change the database from one
CONSISTENT STATE to another
• DBMS transactions must be atomic, consistent, isolated and durable
• If the database were in an inconsistent state before a transaction, it
would remain in the inconsistent state after the transaction.
States of Transactions
• Active State
• Partially Committed
• Committed State
• Failed State
• Terminated State
State of Transactions
ACID Properties
• Atomicity,
• Consistency,
• Isolation,
• Durability
Types of Transactions
• Based on Application areas

• Based on Actions

• Based on Structure
Schedule
Initial Product Quantity is 10
Transaction 1: Update Product Quantity to 50
Transaction 2: Read Product Quantity
Type of equivalence
1. RESULT EQUIVALENCE
2. View Equivalence
3. CONFLICT Equivalence
Serializability
• Conflict

• View
Data warehouse
Data warehouse


Charactheristic
Operations
Operations
N dimension’s datamodell’s
Business intelligense
Goals
Data warehouse vs data modells
OLTP Data warehouse
Domináns műveletek Maintenance (updating) Complex queries involving
operations involving data large data sets. Grouping
involved in a transaction: and ranking of individuals
insertion, modification, (objects, events) according
deletion to certain criteria, as well
as according to a given
grouping or
hierarchyreaching

Optimum-célkitűzés Improving the efficiency of Improving the efficiency of


maintenance operations: queries: acceptable
acceptable transaction response time
processing time
OLTP Data warehouse
Modell Normalization, 2Dimension Multi dimensional (N dimension),
data block

DB technology Relational database. Two versions


Fundamentallyaccess by content - 1. Relational database with table
slower. Navigation by foreign key relationships showing a star
structure.
2. 2. Multidimensional database.
In the case of the latter version:
basically access by address -
faster; based on navigation
indicator

You might also like