Nothing Special   »   [go: up one dir, main page]

Introduction To Databases

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 39

Introduction to

Databases
Database Systems
What is database and write its types
A database is an organized collection of data.

Types:
There are two common types of databases
 Non-Relational
 Relational
Other Types of database
 Centralized database
 Distributed database
 No SQL Database
 Cloud database
 Network database
 Object Oriented database
 Hierarchical database
Non-Relational Database
In a non-relational database, data is stored in key-value pairs.
For example:
Here, customers' data are stored in key-value pairs.
Commonly used non-relational database management systems (Non-RDBMS) are
MongoDB, Amazon DynamoDB, Redis, etc.
Relational Database
In a relational database, data is stored in tabular format.
For example
Here, customers is a table inside the database.
The first row is the attributes of the table. Each row after that contains the data of a customer.
In a relational database, two or more tables may be related to each other. Hence the
term Relational. For example,
Here, orders and customers are related through customer_id.

Commonly used relational database management systems (RDBMS) are MySQL,


PostgreSQL, MSSQL, Oracle etc.
Comparison to file system
 File systems are used to manage files and directories, and provide basic
operations for creating, deleting, renaming, and accessing files. They
typically store data in a hierarchical structure, where files are organized in
directories and subdirectories. File systems are simple and efficient, but they
lack the ability to manage complex data relationships and ensure data
consistency.
 On the other hand, DBMS is a software system designed to manage large
amounts of structured data, and provide advanced operations for storing,
retrieving, and manipulating data. DBMS provides a centralized and organized
way of storing data, which can be accessed and modified by multiple users or
applications. DBMS offers advanced features like data validation, indexing,
transactions, concurrency control, and backup and recovery mechanisms.
DBMS ensures data consistency, accuracy, and integrity by enforcing data
constraints, such as primary keys, foreign keys, and data types.
Hierarchical Structure
 Data Validation: Checking the accuracy and quality of source data before
using, importing or processing data.
 Indexing: A technique that helps to speed up database querying by providing a
way to quickly look up requested data.
 Concurrency Control: A mechanism that ensures that multiple transactions or
requests can access a shared database or resource without conflict.
 Data consistency: The state of data being accurate, complete, and correct
across all related systems, applications, and databases. OR You can say that
the state of data in which all copies or instances are the same across all
systems and databases.
Data Modeling
Data modelling is the first step in the process of database design. This step is
sometimes considered to be a high-level and abstract design phase, also referred
to as conceptual design. The aim of this phase is to describe:
 The data contained in the database (e.g., entities: students, lecturers,
courses, subjects)
 The relationships between data items (e.g., students are supervised by
lecturers; lecturers teach courses)
 The constraints on data (e.g., student number has exactly eight digits; a
subject has four or six units of credit only)
In the second step, the data items, the relationships and the constraints are all
expressed using the concepts provided by the high-level data model. Because
these concepts do not include the implementation details, the result of the data
modelling process is a (semi) formal representation of the database structure.
This result is quite easy to understand so it is used as reference to make sure
that all the user’s requirements are met.
High-level Conceptual Data Models

High-level conceptual data models provide concepts for presenting data in ways
that are close to the way people perceive data. A typical example is the entity
relationship model, which uses main concepts like entities, attributes and
relationships. An entity represents a real-world object such as an employee or a
project. The entity has attributes that represent properties such as an
employee’s name, address and birthdate. A relationship represents an association
among entities; for example, an employee works on many projects.
A relationship exists between the employee and each project.
Database Design
The third step is database design. During this step, we might have two sub-steps:
 database logical design, which defines a database in a data model of a
specific DBMS.
 database physical design, which defines the internal database storage
structure, file organization or indexing techniques.
These two sub-steps are database implementation and operations/user interfaces
building steps.
In the database design phases, data are represented using a certain data model.
The data model is a collection of concepts or notations for describing data, data
relationships, data semantics and data constraints. Most data models also include
a set of basic operations for manipulating data in the database.
Entity
An entity is referred to as an object or thing that exists in the real world. For
example, customer, car, pen, etc.
An entity has some attributes which depict the entity's characteristics. For
example, an entity "Student" has attributes such as "Student_roll_no",
"Student_name", "Student_subject", and "Student_marks".

Kinds of Entity
 Tangible Entity
 Intagible Entity
Tangible Entity

It is an entity in DBMS, which is a physical object that we can touch or see. In


simple words, an entity that has a physical existence in the real world is called a
tangible entity.
For example, in a database, a table represents a tangible entity because it
contains a physical object that we can see and touch in the real world. It
includes colleges, bank lockers, mobiles, cars, watches, pens, paintings, etc.
Intangible Entity

It is an entity in DBMS, which is a non-physical object that we cannot see or


touch. In simple words, an entity that does not have any physical existence in
the real world is known as an intangible entity.
For example, a bank account logically exists, but we cannot see or touch it.
Entity Type
A collection of entities with general characteristics is known as an entity type.
For example, a database of a corporate company has entity types such as
employees, departments, etc. In DBMS, every entity type contains a set of
attributes that explain the entity.
 The Employee entity type can have attributes such as name, age, address,
phone number, and salary.
 The Department entity type can have attributes such as name, number, and
location in the department.
Kinds of Entity Type
There are two kinds of entity type,
 Strong Entity Type
It is an entity that has its own existence and is independent. The entity
relationship diagram represents a strong entity type with the help of a single
rectangle. Below is the ERD of the strong entity type:
Weak Entity Type
It is an entity that does not have its own existence and relies on a strong entity for
its existence.
The Entity Relationship Diagram represents the weak entity type using double
rectangles. Below is the ERD of the weak entity type:
In the above example, "Address" is a weak entity type with attributes such as
House No., City, Location, and State.
The relationship between a strong and a weak entity type is known as an
identifying relationship.
Using a double diamond, the Entity-Relationship Diagram represents a
relationship between the strong and the weak entity type.
Let us see an example of the relationship between the Strong entity type and
weak entity type with the help of ER Diagram.
Entity Set
An entity set is a group of entities of the same entity type.
For example, an entity set of students, an entity set of motorbikes, an entity of
smartphones, an entity of customers, etc.
Entity sets can be classified into two types:
 Strong Entity Set
 Weak Entity Set
Strong Entity Set
In a DBMS, a strong entity set consists of a primary key.
For example, an entity of motorbikes with the attributes, motorbike's
registration number, motorbike's name, motorbike's model, and motorbike's
colour.

Below is the representation of a strong entity set in tabular form.


ER diagram of Strong Entity Set
Weak Entity Set:
In a DBMS, a weak entity set does not contain a primary key.
For example, An entity of smartphones with its attributes, phone's name, phone's
colour, and phone's RAM.

Below is the representation of a weak entity set in tabular form


ER diagram of Weak Entity Set
Attributes
In a database management system (DBMS), an attribute is a piece of data that
describes an entity.
For example
In a customer database, the attributes might be name, address, and phone
number.
Each attribute has a specific data type, such as string, integer, or date.
Attributes can be used to describe both simple and complex entities. A product,
for example, might be described by a single attribute such as name or price.
However, it can also be described by multiple attributes such as name, price, and
date of manufacture. In addition, some attributes might be used to describe
other attributes.
For example
An attribute called "color" might describe a product's color.
Why we use attributes

Attributes are important because they help to describe the entities in a


database. They also help to distinguish one entity from another. For example, if
two customers have the same name, we can use their address attribute to
identify them. Similarly, if two products have the same name, we can use their
price or manufacturer attributes to identify them.

Attributes also play an important role in making databases searchable. For


example, if we want to find all customers who live in a particular zip code, we
can use the customer's address attribute to search for them. Or if we want to
find all products that cost less than $10, we can use the product's price attribute
to search for them.
Types of attributes
Simple Attributes

Simple attributes are those that cannot be further divided into sub-attributes.
For example
A roll number of a student or the employee identification number.
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.
Single Valued Attributes

Single-valued attributes can only have one value, and these values remain
constant.
For example
A person's Social Security Number is a single-valued attribute.
Multivalued Attributes

Multivalued attributes can have more than one value.


For example
A person may have multiple email addresses or phone numbers.
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.
Complex Attributes

The complex attribute in DBMS involves both multivalued and composite


attributes.
For example
Someone might have more than one house, and each house might have more than
one phone.
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.
Keys
Keys are used to uniquely identify any record or row of data from the table. It is
also used to establish and identify relationships between tables.
Following are the types of Keys:
 Primary Key: It is the first key used to identify one and only one instance of
an entity uniquely.
 Super Key: Super key is an attribute set that can uniquely identify a tuple. A
super key is a superset of a candidate key.
 Candidate Key: A candidate key is an attribute or set of attributes that can
uniquely identify a tuple.
 Alternate Key: The total number of the alternate keys is the total number of
candidate keys minus the primary key.
 Foreign Key: Foreign keys are the column of the table used to point to the
primary key of another table.
 Composite Key: Whenever a primary key consists of more than one attribute,
it is known as a composite key. This key is also known as Concatenated Key.
Types of Relationship

Following are the types of the Relationship

 One to One relationship


 One to many or many to one relationship
 Many to many relationships
One to One relationship

A one-to-one relationship is a link between two tables where each record in one
table only appears once in the other table.
For example
A school database might have a one-to-one relationship between students and
their student IDs, where each student has only one ID and each ID is assigned to
only one person.
One to many or many to one relationship

When one row in table “A” is linked to many rows in table “B” then it is called as
one to many relationship.
Many to many relationships
A many-to-many relationship in a database occurs when one or more items in one
table can have a relationship to one or more items in another table.
For example, a customer can have multiple orders placed by other customers,
and one order can contain one or more instances of multiple products.

You might also like