Databases and Data Modelling
Databases and Data Modelling
Presented By :
Jagjit Singh
Senior Technical Trainer
jagjit.e15190@cumail.in
Relational Databases
A relational database organizes data into rows and columns, which collectively
form a table. Data is typically structured across multiple tables, which can be
joined together via a primary key or a foreign key. These unique identifiers
demonstrate the different relationships which exist between tables, and these
relationships are usually illustrated through different types of data models.
Analysts use SQL queries to combine different data points and summarize
business performance, allowing organizations to gain insights, optimize
workflows, and identify new opportunities.
For example
While a relational database organizes data based off a relational data model, a
relational database management system (RDBMS) is a more specific reference to
the underlying database software that enables users to maintain it. These
programs allow users to create, update, insert, or delete data in the system, and
they provide:
Data structure
Multi-user access
Privilege control
Network access
Conceptual and Physical Data Models
Conceptual Data Model: This Data Model defines WHAT the system contains. This
model is typically created by Business stakeholders and Data Architects. The purpose is to
organize, scope and define business concepts and rules.
Logical Data Model: Defines HOW the system should be implemented regardless of the
DBMS. This model is typically created by Data Architects and Business Analysts. The
purpose is to developed technical map of rules and data structures.
Physical Data Model: This Data Model describes HOW the system will be implemented
using a specific DBMS system. This model is typically created by DBA and developers.
The purpose is actual implementation of the database.
Characteristics of a conceptual data model
Describes data needs for a single project but could integrate with
other logical data models based on the scope of the project.
Designed and developed independently from the DBMS.
Data attributes will have datatypes with exact precisions and length
Characteristics of a physical data model:
The physical data model describes data need for a single project or application though it
maybe integrated with other physical data models based on project scope.
Data Model contains relationships between tables that which addresses cardinality and
nullability of the relationships.
Developed for a specific version of a DBMS, location, data storage or technology to be
used in the project.
Columns should have exact datatypes, lengths assigned and default values.
Primary and Foreign keys, views, indexes, access profiles, and authorizations, etc. are
defined.
Advantages and Disadvantages of Data Model:
Data modeling is the process of developing data model for the data to be stored in a Database.
Data Models ensure consistency in naming conventions, default values, semantics, security while ensuring
quality of the data.
Data Model structure helps to define the relational tables, primary and foreign keys and stored procedures.
There are three types of conceptual, logical, and physical.
The main aim of conceptual model is to establish the entities, their attributes, and their relationships.
Logical data model defines the structure of the data elements and set the relationships between them.
A Physical Data Model describes the database specific implementation of the data model.
The main goal of a designing data model is to make certain that data objects offered by the functional
team are represented accurately.
The biggest drawback is that even smaller change made in structure require modification in the entire
application.
Entity and Attributes
An entity is a distinct real-world thing, such as a person, a place, or a concept, that can be
uniquely identified. It's an object that stands out from the crowd.
Types of Entity:
An entity can be of two types :
Tangible Entity: The term tangible entities refer to the physical entities that exist in the
real world.
Example: a student, a keyboard, a bank locker, car, etc.
Intangible Entity: Entities with solely a cognitive existence and no physical existence.
Example: a Google Account, a bank account etc.
Example:
In this particular example given below, we have a table named “Professor,” which contains
multiple entities having attributes(Professor ID, Professor Name, Professor City, Professor
Salary) by which we can understand that every entity contains a unique Professor ID,
which is the key attribute of the table which helps to distinguish between the entities.
A group of entities with the same set of properties is referred to as an entity set. Each entity
in an entity set has its own set of attribute values that distinguishes it from the other
entities in the table. The characteristics of no two entities in an entity set will have
identical values.
The Table in a database represents an entity set. The Student Table, which has numerous
entities, is shown below. Even though both kids have the name Jhoson, they are uniquely
identified since they have separate roll numbers.
Attributes
Simple attributes are those that cannot be further divided into sub-
attributes.
For example, A student's roll number of a student or the employee
identification number. These attributes are usually assigned by an
organization and are used to identify an individual within that
organization uniquely. Databases and other systems often use simple
attributes to track and manage information.
Composite Attributes
Composite attributes are made up of two or more simple attributes. For example, a person's
address may be a composite attribute that is made up of the person's street address, city,
state, and zip code. Composite attributes can be used to create more complex data models
and can be helpful when trying to represent data in a concise way.
Single Valued Attributes
Single-valued attributes can only have one value. For example, a person's Social Security
Number is a single-valued attribute. Social Security Numbers are used to uniquely identify
individuals in the United States and are, therefore, single-valued attributes.
Examples of single-valued attributes include employee numbers, customer numbers, and
product codes. Single-valued attributes are typically used to provide a unique identifier for
an entity and are often used in databases.
Multivalued Attributes
Multivalued attributes can have more than one value. For example,
a person may have multiple email addresses or phone numbers.
Multivalued attributes in DBMS are often used to store information
about relationships between entities. For instance, an employee
entity might have a multivalued attribute called "dependents" that
stores the names of the employee's dependents. Multivalued
attributes can also be used to represent hierarchical data.
Derived Attributes
Derived attributes are based on other attributes and are not stored directly in the database.
For example: Consider a database of employees. Each employee has a date of birth, and
we might want to calculate their age. However, age is a derived attribute because it can be
determined from the date of birth. As such, it would not make sense to store it directly in
the database. Here is an example diagram of a derived attribute in DBMS:
Key Attributes
DBMS's key attributes are used to uniquely identify each row in a table. Usually, there is
more than one key attribute in a table (primary key and foreign key).
For example: In a table of employees, the employee ID would be the primary key, while
the manager ID would be the foreign key.
Stored Attributes
In a DBMS, stored attributes are the data that remain constant and fixed for an entity
instance. These values help in deriving the derived attributes.
For example: consider a customer entity in a bank. The customer's name, age, and address
would be stored attributes. The customer's account balance (a derived attribute) could be
calculated based on the transactions (another stored attribute) associated with the customer.
UNIQUEIDENTIFIER Data Type
A relationship in DBMS is the way in which two or more data sets are linked, i.e., any
association between two entity types is called a relationship. So entity takes part in the
relationship, and it is represented by a diamond shape.
For example
A teacher teaches students. Here, " teaches " is a relationship and this is the relationship
between a Teacher entity and a Student entity.
We have two entity types of 'Customer'(Customer_id, Name, City, Phone) and
'Account'(Account_no, Type, Balance). We store the data of 'Customer' in one table and his
accounts details in the 'Account' table. Now, to link these two tables we need to insert the
primary key 'Customer_id' of the 'Customer' table in the 'Account' table. This key acts as a
foreign key for the 'Account' table and refers to a column with the same name in the
'Customer' table. This is how a relationship between two tables is established.
Types of relationships
One-to-One Relationship
One-to-Many or Many-to-One Relationship
Many-to-Many Relationship
One-to-One Relationship
Such a relationship exists when each record of one table is related to only one record of the
other table.
For example
Such a relationship exists when each record of one table can be related to one or more than
one record of the other table. This relationship is the most common relationship found. A
one-to-many relationship can also be said as a many-to-one relationship depending upon
the way we view it.
For example, If there are two entity type ‘Customer’ and ‘Account’ then each ‘Customer’
can have more than one ‘Account’ but each ‘Account’ is held by only one ‘Customer’. In
this example, we can say that each Customer is associated with many Account. So, it is a
one-to-many relationship. But, if we see it the other way i.e many Account is associated
with one Customer then we can say that it is a many-to-one relationship.
Many-to-Many Relationship
Such a relationship exists when each record of the first table can be
related to one or more than one record of the second table and a
single record of the second table can be related to one or more than
one record of the first table. A many-to-many relationship can be
seen as a two one-to-many relationship which is linked by a 'linking
table' or 'associate table'. The linking table links two tables by
having fields which are the primary key of the other two tables. We
can understand this with the following example.
Example:
If there are two entity type ‘Customer’ and ‘Product’ then each customer can buy more
than one product and a product can be bought by many different customers.
Entity Relationship Modeling (ERDs)
What is an ER diagram?
An Entity Relationship (ER) Diagram is a type of flowchart that illustrates how “entities” such
as people, objects or concepts relate to each other within a system. ER Diagrams are most
often used to design or debug relational databases in the fields of software engineering,
business information systems, education and research. Also known as ERDs or ER Models,
they use a defined set of symbols such as rectangles, diamonds, ovals and connecting lines to
depict the interconnectedness of entities, relationships and their attributes.
Uses of entity relationship diagrams
Database design:
ER diagrams are used to model and design relational databases, in terms of logic and
business rules (in a logical data model) and in terms of the specific technology to be
implemented (in a physical data model.) In software engineering, an ER diagram is
often an initial step in determining requirements for an information systems project.
It’s also later used to model a particular database or databases.
Database troubleshooting:
ER diagrams are used to analyze existing databases to find and resolve problems in logic
or deployment. Drawing the diagram should reveal where it’s going wrong.
Business information systems:
The diagrams are used to design or analyze relational databases used in business processes.
Any business process that uses fielded data involving entities, actions and interplay can
potentially benefit from a relational database.
Business process re-engineering (BPR): ER diagrams help in analyzing
databases used in business process re-engineering and in modeling a new
database setup.
Education: Databases are today’s method of storing relational information for
educational purposes and later retrieval, so ER Diagrams can be valuable in
planning those data structures.
Research: Since so much research focuses on structured data, ER diagrams can
play a key role in setting up useful databases to analyze the data.
The components and features of an ER diagram
Entity
A definable thing—such as a person, object, concept or event—that can have data stored
about it. Think of entities as nouns. Examples: a customer, student, car or product.
Typically shown as a rectangle.
Entity set: Same as an entity type, but defined at a particular point in time, such as students
enrolled in a class on the first day. Other examples: Customers who purchased last month,
cars currently registered in Florida. A related term is instance, in which the specific person
or car would be an instance of the entity set.
Entity categories: Entities are categorized as strong, weak or associative. A strong
entity can be defined solely by its own attributes, while a weak entity cannot. An
associative entity associates entities (or elements) within an entity set.
Entity keys:
Refers to an attribute that uniquely defines an entity in an entity set. Entity keys can be
super, candidate or primary. Super key: A set of attributes (one or more) that together
define an entity in an entity set.
Candidate key:
A minimal super key, meaning it has the least possible number of attributes to
still be a super key. An entity set may have more than one candidate key. Primary key: A
candidate key chosen by the database designer to uniquely identify the entity set. Foreign
key: Identifies the relationship between entities.
ERD symbols and notations
THANKS