Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 13

Database Management System

 Database management system is a software which is used to manage the database. For example:
MySQL, Oracle, etc are a very popular commercial database which is used in different applications.
 DBMS provides an interface to perform various operations like database creation, storing data in it,
updating data, creating a table in the database and a lot more.
 It provides protection and security to the database. In the case of multiple users, it also maintains data
consistency.

Advantages of DBMS

Controls database redundancy: It can control data redundancy because it stores all the data in one
single database file and that recorded data is placed in the database.
Data sharing: In DBMS, the authorized users of an organization can share the data among multiple
users.
Easily Maintenance: It can be easily maintainable due to the centralized nature of the database system.
Reduce time: It reduces development time and maintenance need.
Backup: It provides backup and recovery subsystems which create automatic backup of data from
hardware and software failures and restores the data if required.
multiple user interface: It provides different types of user interfaces like graphical user interfaces,
application program interfaces

Advantages/ Characteristics of DBMS

Controls database redundancy: It can control data redundancy because it stores all the data in one
single database file and that recorded data is placed in the database.
Data sharing: In DBMS, the authorized users of an organization can share the data among multiple users.
Easily Maintenance: It can be easily maintainable due to the centralized nature of the database system.
Reduce time: It reduces development time and maintenance need.
Backup: It provides backup and recovery subsystems which create automatic backup of data from
hardware and software failures and restores the data if required.
multiple user interface: It provides different types of user interfaces like graphical user interfaces,
application program interfaces.
A database management system is able to store any kind of data in a database.
 The database management system has to support ACID (atomicity, consistency, isolation, durability)
properties.
 The Database management system allows so many users to access databases at the same time.
 Backup and recovery are the two main methods which allow users to protect the data from damage or
loss.
 It also provides multiple views for different users in a single organization.
 It follows the concept of normalization which is helpful to minimize the redundancy of a relation.
 It also provides users query language, helpful to insert, retrieve, update, and delete the data in a
database.

Strong Entity:
A strong entity is not dependent on any other entity in the schema. A strong entity will always have a
primary key. Strong entities are represented by a single rectangle. The relationship of two strong entities
is represented by a single diamond.
Various strong entities, when combined together, create a strong entity set.
Weak Entity:
A weak entity is dependent on a strong entity to ensure its existence. Unlike a strong entity, a weak entity
does not have any primary key. It instead has a partial discriminator key. A weak entity is represented by
a double rectangle.
The relation between one strong and one weak entity is represented by a double diamond. This
relationship is also known as identifying relationship.
Entity Relationship Diagram (ERD) Symbols and Notations.
There are three basic elements in an ER Diagram: entity, attribute, relationship. There are more elements
which are based on the main elements. They are weak entity, multi valued attribute, derived attribute,
weak relationship, and recursive relationship.

Needs of Normalization : Normalization is a technique for organizing data in a database. It is important that a
database is normalized to minimize redundancy (duplicate data) and to ensure only related data is stored
in each table. It also prevents any issues stemming from database modifications such as insertions,
deletions, and updates.Normalization helps to reduce redundancy and complexity by examining new data
types used in the table. It is helpful to divide the large database table into smaller tables and link them
using relationship. It avoids duplicate data or no repeating groups into a table.

Lock:
A lock is a data variable which is associated with a data item. This lock signifies that operations that can
be performed on the data item. Locks in DBMS help synchronize access to the database items by
concurrent transactions. All lock requests are made to the concurrency-control manager.there is one lock
for each data item in the database.

Data Manipulation Language Commends:


DML stands for Data Manipulation Language. It is used for accessing and manipulating data in a
database. It handles user requests.
Select: It is used to retrieve data from a database.
Insert: It is used to insert data into a table.
Update: It is used to update existing data within a table.
Delete: It is used to delete all records from a table.
Merge: It performs UPSERT operation, i.e., insert or update operations.
Call: It is used to call a structured query language or a Java subprogram.

Data Definition Language


 DDL stands for Data Definition Language. It is used to define database structure or pattern.
 It is used to create schema, tables, indexes, constraints, etc. in the database.
 Using the DDL statements, you can create the skeleton of the database.
 Data definition language is used to store the information of metadata like the number of tables and
schemas, their names, indexes, columns in each table, constraints, etc.

Create: It is used to create objects in the database.


Alter: It is used to alter the structure of the database.
Drop: It is used to delete objects from the database.
Truncate: It is used to remove all records from a table.
Rename: It is used to rename an object.
Comment: It is used to comment on the data dictionary.

These commands are used to update the database schema that's why they come under Data definition language.
.

Aggregate functions: Aggregate functions in DBMS take multiple rows from the table and return a value
according to the query.
AVG – calculates the average of a set of values.
COUNT – counts rows in a specified table or view.
MIN – gets the minimum value in a set of values.
MAX – gets the maximum value in a set of values.
SUM – calculates the sum of values

All the aggregate functions are used in Select statement.


Syntax −
SELECT <FUNCTION NAME> (<PARAMETER>) FROM <TABLE NAME>
AVG Function
Select AVG(salary) from Employee
COUNT Function
The count function returns the number of rows in the result. It does not count the null values.
Select COUNT(*) from Employee where Salary > 20000;
MAX Function
The MAX function is used to find maximum value in the column that is supplied as a parameter. It can be
used on any type of data.
Select MAX(salary) from Employee
SUM Function
This function sums up the values in the column supplied as a parameter.

Examples:
Now let us understand each Aggregate function with a
Id Name Salary
1 A 80
2 B 40
3 C 60
4 D 70
5 E 60
6 F Null

Count():
Count(*): Returns total number of records .i.e 6.
Count(salary): Return number of Non Null values over the column salary. i.e 5.
Count(Distinct Salary): Return number of distinct Non Null values over the column salary .i.e 4

Sum():
sum(salary): Sum all Non Null values of Column salary i.e., 310
sum(Distinct salary): Sum of all distinct Non-Null values i.e., 250

Avg():
Avg(salary) = Sum(salary) / count(salary) = 310/5
Avg(Distinct salary) = sum(Distinct salary) / Count(Distinct Salary) = 250/4

Min():
Min(salary): Minimum value in the salary column except NULL i.e., 40.
Max()
Max(salary): Maximum value in the salary i.e., 80.
Database recovery :
Database recovery is the process of restoring the database to a correct (consistent) state in the event of a
failure. In other words, it is the process of restoring the database to the most recent consistent state that
existed shortly before the time of system failure.
There are four different recovery techniques are available in the Database.
 Mirroring.
 Recovery using Backups.
 Recovery using Transaction Logs.
 Shadow Paging.

DBMS Architecture
 The DBMS design depends upon its architecture. The basic client/server architecture is used to deal with
a large number of PCs, web servers, database servers and other components that are connected with
networks.
 The client/server architecture consists of many PCs and a workstation which are connected via the
network.
 DBMS architecture depends upon how users are connected to the database to get their request done.

Types of DBMS Architecture

Tier Architecture
In this architecture, the database is directly available to the user. It means the user can directly sit on the DBMS
and uses it.
Any changes done here will directly be done on the database itself. It doesn't provide a handy tool for end users.
The 1-Tier architecture is used for development of the local application, where programmers can directly
communicate with the database for the quick response.

The 2-Tier architecture is same as basic client-server. In the two-tier architecture, applications on the client end
can directly communicate with the database at the server side. For this interaction, API's like: ODBC, JDBC are
used.
 The user interfaces and application programs are run on the client-side.
 The server side is responsible to provide the functionalities like: query processing and transaction
management.
 To communicate with the DBMS, client-side application establishes a connection with the server side.
Tier Architecture
The 3-Tier architecture contains another layer between the client and server. In this architecture, client can't
directly communicate with the server.
 The application on the client-end interacts with an application server which further communicates with
the database system.
 End user has no idea about the existence of the database beyond the application server. The database also
has no idea about any other user beyond the application.
 The 3-Tier architecture is used in case of large web application.

ER model
 ER model stands for an Entity-Relationship model. It is a high-level data model. This model is used to
define the data elements and relationship for a specified system.
 It develops a conceptual design for the database. It also develops a very simple and easy to design view of
data.
 In ER modeling, the database structure is portrayed as a diagram called an entity-relationship diagram.

For example, suppose we design a school database. In this database, the student will be an entity with attributes
like address, name, id, age, etc. The address can be another entity with attributes like city, street name, pin code,
etc and there will be a relationship between them.

Component of ER Diagram
Entity:
 An entity may be any object, class, person or place. In the ER diagram, an entity can be represented as
rectangles.
 Consider an organization as an example- manager, product, employee, department etc. can be taken as an
entity.

Weak Entity

An entity that depends on another entity called a weak entity. The weak entity doesn't contain any key attribute of
its own. The weak entity is represented by a double rectangle.

Attribute
The attribute is used to describe the property of an entity. Eclipse is used to represent an attribute.
For example, id, age, contact number, name, etc. can be attributes of a student.

Composite Attribute
An attribute that composed of many other attributes is known as a
composite attribute. The composite attribute is represented by an ellipse,
and those ellipses are connected with an ellipse.

Multivalued Attribute
An attribute can have more than one value. These attributes are known as a
multivalued attribute.
The double oval is used to represent multivalued attribute.

For example, a student can have more than one phone number.

Derived Attribute

An attribute that can be derived from other attribute is known as a derived attribute. It
can be represented by a dashed ellipse.

For example, A person's age changes over time and can be derived from another
attribute like Date of birth.
Relationship

A relationship is used to describe the relation between


entities. Diamond or rhombus is used to represent the
relationship.

Types of relationship are as follows:

One-to-One Relationship

When only one instance of an entity is associated with the relationship, then it is known as one to one
relationship.

For example, If there are two entities ‘Person’ (Id, Name,


Age, Address)and ‘Passport’(Passport_id, Passport_no).
So, each person can have only one passport and each
passport belongs to only one person.

One-to-many relationship

When only one instance of the entity on the left, and more than one instance of an entity on the right associates
with the relationship then this is known as a one-to-many relationship.

For example,

Many-to-one relationship

When more than one instance of the entity on the left, and only one instance of an entity on the right associates
with the relationship then it is known as a many-to-one relationship.

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

When more than one instance of the entity on the left, and more than one instance of an entity on the right
associates with the relationship then it is known as a many-to-many relationship.

For 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.
Schema:
The overall design of the database is called database schema. Schema will not be changed frequently. It is the
logical structure of a database. It does not show the data in the database.

The schema is pictorially represented as follows −

Types of Schema

Physical schema − It is a database design at the physical level.It is hidden below the logical schema and can be
changed easily without affecting the application programs.
Logical schema − It is a database design at the logical level. Programmers construct applications using logical
schema.
External − It is schema at view level. It is the highest level of a schema which defines the views for end users.
Generally the Database Management System (DBMS) assists one physical schema, one logical schema and
several sub or external schemas.
Database schema refers to the format and layout of the database in which the data will be stored. It is the one
thing that remains the same throughout unless otherwise modified. It defines the structure of what type of data and
how it will be stored.
Example

A database schema for a person will have fields for name, email, phone and address as shown below −

Person

Name Email Phone no

Instance
Instance or extension or database state is a collection of information that stored in a database at a particular
moment is called an instance of the database. The Database instance refers to the information stored in the
database at a given point of time. Thus, it is a dynamic value which keeps on changing.
Example
A database instance for the Person database can be (User1,emai.com,11345679,addr) So the person construct will
contain their individual entities in the attributes called as instance. This is shown below −
Person
Name Email Phone no
BOB kksd@yasd.com 2343435
JANU werwr@sdas.in 5345464
PRIYA wefrwer@sdf.com 2342342
Relational Calculus
 Relational calculus is a non-procedural query language. In the non-procedural query language, the user is
concerned with the details of how to obtain the end results.
 The relational calculus tells what to do but never explains how to do.

Types of Relational calculus:

Tuple Relational Calculus (TRC)


The tuple relational calculus is specified to select the tuples in a relation. In TRC, filtering variable uses the tuples
of a relation.
The result of the relation can have one or more tuples.

Notation:

1. {T | P (T)} or {T | Condition (T)} Where


T is the resulting tuples

P(T) is the condition used to fetch T.

For example:

1. { T.name | Author(T) AND T.article = 'database' }

OUTPUT: This query selects the tuples from the AUTHOR relation. It returns a tuple with 'name' from Author
who has written an article on 'database'.

TRC (tuple relation calculus) can be quantified. In TRC, we can use Existential (∃) and Universal Quantifiers (∀).

For example:

{ R| ∃T ∈ Authors(T.article='database' AND R.name=T.name)}

Output: This query will yield the same result as the previous one.

Domain Relational Calculus (DRC)


The second form of relation is known as Domain relational calculus. In domain relational calculus, filtering
variable uses the domain of attributes.
Domain relational calculus uses the same operators as tuple calculus. It uses logical connectives 𝖠 (and),
∨ (or) and ┓ (not).
It uses Existential (∃) and Universal Quantifiers (∀) to bind the variable.

Notation:
1. { a1, a2, a3, ..., an | P (a1, a2, a3, ... ,an)}
Where
a1,a2 are attributes
P stands for formula built by inner attributes
For example:
{< article, page, subject > | ∈ javatpoint 𝖠 subject = 'database'}
Output: This query will yield the article, page, and subject from the relational javatpoint, where the subject is a
database.
Normal Form in Normalization:
 Normalization is the process of organizing the data in the database.
 Normalization is used to minimize the redundancy from a relation or set of relations. It is also used to
eliminate the undesirable characteristics like Insertion, Update and Deletion Anomalies.
 Normalization divides the larger table into the smaller table and links them using relationship.
 The normal form is used to reduce redundancy from the database table.

The normal form is used to reduce redundancy from the database.


Normal FormDescription
1NF A relation is in 1NF if it contains an atomic value.
2NF A relation will be in 2NF if it is in 1NF and all non-key attributes are fully
functional dependent on the primary key.
3NF A relation will be in 3NF if it is in 2NF and no transition dependency
exists.
4NF A relation will be in 4NF if it is in Boyce Codd normal form and has no
multi-valued dependency.
5NF A relation is in 5NF if it is in 4NF and not contains any join dependency
and joining should be lossless.

Explain Plan: It has the parameter of explaining data.


Lock Table: It controls concurrency

Boyce-Codd Normal Form

Boyce-Codd Normal Form (BCNF) is an extension of Third Normal Form on strict terms. BCNF states that

Boyce-Codd Normal Form (BCNF) is one of the forms of database normalization. A database table is in BCNF if
and only if there are no non-trivial functional dependencies of attributes on anything other than a superset of a
candidate key. BCNF is also sometimes referred to as 3.5NF, or 3.5 Normal Form

For any non-trivial functional dependency, X → A, X must be a super-key.

In the above image, Stu_ID is the super-key in the relation Student_Detail and Zip is the super-key in the relation
ZipCodes. So,
Stu_ID → Stu_Name, Zip and
Zip → City

Which confirms that both the relations are in BCNF


HDAM or PHDAM databases consist of two parts: a root addressable area and an overflow area.

The root addressable area contains root segments and is the primary storage area for dependent segments in a
database record. The overflow area is for the storage of segments that do not fit in the root addressable area. You
specify the size of the root addressable area in the relative block number (RBN) operand of the RMNAME
parameter in the DBD statement. For PHDAM, you can also use the HALDB Partition Definition utility to specify
the size of the root addressable area. You also specify the maximum number of bytes of a database record to be
stored in the root addressable area by using the BYTES operand of the RMNAME parameter in the DBD
statement. For PHDAM databases, you can use the HALDB Partition Definition utility to specify the maximum
number of bytes in the root addressable area.

The following figure shows example SKILL database records.

Figure 1. Two example SKILL records in an HD database

The following figure shows how these records are stored in a HDAM or
HIDAM database.

Figure 2. HDAM or PHDAM database records in storage

When the database is initially loaded, the root and each


dependent segment are put in the root addressable area until
the next segment to be stored will cause the total space used
to exceed the amount of space you specified in the BYTES
operand. At this point, all remaining dependent segments in
the database record are stored in the overflow area.

In an HDAM or a PHDAM database, the order in which you


load database records does not matter. The user randomizing
module determines where each root is stored. However, as
with all types of databases, when the database is loaded, all
dependents of a root must be loaded in hierarchical sequence
following the root.

To store an HDAM or a PHDAM database record, the


randomizing module takes the root's key and, by hashing or
some other arithmetic technique, computes an RBN or CI
number and a RAP number within the block or CI. The
module gives these numbers to IMS, and IMS determines
where in the root addressable area to store the root. The RBN
or CI tells IMS in which CI or block (relative to the
beginning of the data set) the RAP will be stored. The RAP
number tells which RAP in the CI or block will contain the address of the root. During load, IMS stores the root
and as many of its dependent segments that will fit (based on the bytes operand) in the root addressable area.

When the database is initially loaded, it puts the root and segments in the first available space in the specified CI
or block, if this is possible. IMS then puts the 4-byte address of the root in the RAP of the CI or block designated
by the randomizing module. RAPs only exist in the root addressable area. If space is not available in the root
addressable area for a root, it is put in the overflow area. The root, however, is chained from a RAP in the root
addressable area.

You might also like