DBMS Essentials for IT Professionals
DBMS Essentials for IT Professionals
Advantages of DBMS
o 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.
o Data sharing: In DBMS, the authorized users of an organization can share the data among multiple
users.
o Easily Maintenance: It can be easily maintainable due to the centralized nature of the database system.
o Reduce time: It reduces development time and maintenance need.
o Backup: It provides backup and recovery subsystems which create automatic backup of data
from hardware and software failures and restores the data if required.
o multiple user interface: It provides different types of user interfaces like graphical user interfaces,
application program interfaces
2. 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.
3. 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.
4. 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.
5. 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.
o 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.
o 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.
o It provides protection and security to the database. In the case of multiple users, it also maintains data
consistency.
DML stands for Data Manipulation Language. It is used for accessing and manipulating data in a database. It
handles user requests.
8. Aggregate functions: Aggregate functions in DBMS take multiple rows from the table and return a value
according to the query.
statement. Syntax −
AVG Function
COUNT Function
The count function returns the number of rows in the result. It does not count the null values.
COUNT(*): Counts all the number of rows of the table including null.
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.
SUM Function
This function sums up the values in the column supplied as a parameter.
o 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.
o Normalization divides the larger table into the smaller table and links them using relationship.
o The normal form is used to reduce redundancy from the database table.
Normal Description
Form
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.
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.
10. 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.
1. DBMS Architecture
o 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.
o The client/server architecture consists of many PCs and a workstation which are connected via the
network.
o DBMS architecture depends upon how users are connected to the database to get their request done.
1- Tier Architecture
o In this architecture, the database is directly available to the user. It means the user can directly sit on the
DBMS and uses it.
o Any changes done here will directly be done on the database itself. It doesn't provide a handy tool for
end users.
o The 1-Tier architecture is used for development of the local application, where programmers can
directly communicate with the database for the quick response.
2- Tier Architecture
o 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.
o The user interfaces and application programs are run on the client-side.
o The server side is responsible to provide the functionalities like: query processing and transaction
management.
o To communicate with the DBMS, client-side application establishes a connection with the server side.
3- Tier Architecture
o The 3-Tier architecture contains another layer between the client and server. In this architecture, client
can't directly communicate with the server.
o The application on the client-end interacts with an application server which further communicates with
the database system.
o 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.
o 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.
o Data sharing: In DBMS, the authorized users of an organization can share the data among multiple
users.
o Easily Maintenance: It can be easily maintainable due to the centralized nature of the database system.
o multiple user interface: It provides different types of user interfaces like graphical user interfaces,
application program interfaces.
o The database management system has to support ACID (atomicity, consistency, isolation, durability)
properties.
o The Database management system allows so many users to access databases at the same time.
o Backup and recovery are the two main methods which allow users to protect the data from damage or
loss.
o It follows the concept of normalization which is helpful to minimize the redundancy of a relation.
o It also provides users query language, helpful to insert, retrieve, update, and delete the data in a
database.
3. ER model
o 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.
o It develops a conceptual design for the database. It also develops a very simple and easy to design view
of data.
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
1. 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.
a. 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.
2. 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.
b. 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.
c. 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.
d. 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.
3. Relationship
A relationship is used to describe the relation between entities. Diamond or rhombus is used to represent the
relationship.
When only one instance of an entity is associated with the relationship, then it is known as one to one
relationship.
For example, A female can marry to one male, and a male can marry to one female.
b. 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, Scientist can invent many inventions, but the invention is done by the only specific scientist.
c. 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, Student enrolls for only one course, but a course can have many students.
d. 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, Employee can assign by many projects and project can have many employees.
a. 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.
b. 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,
c. 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.
d. 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.
5. 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.
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
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
Differences
Example” We take two tables emp table At a moment, what is the value of the database
and dept table.Emp schema is called instance.At t=8 A.M
Name 1 A 5000 d1
Salary 2 B 2000 d2
At t=9 A.M
dept 3
Dept
C
Dept_id
3000
dname
d3
This corresponds to the variable declaration The value of the variable in a program at a point
of a programming language. in time corresponds to an instance of the database
schema.
6. Data Definition Language
o DDL stands for Data Definition Language. It is used to define database structure or pattern.
o It is used to create schema, tables, indexes, constraints, etc. in the database.
o Using the DDL statements, you can create the skeleton of the database.
o 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.
These commands are used to update the database schema that's why they come under Data definition language.
7. Relational Calculus
o 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.
o The relational calculus tells what to do but never explains how to do.
o The tuple relational calculus is specified to select the tuples in a relation. In TRC, filtering variable uses
the tuples of a relation.
Notation:
Where
For example:
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:
o The second form of relation is known as Domain relational calculus. In domain relational calculus,
filtering variable uses the domain of attributes.
o Domain relational calculus uses the same operators as tuple calculus. It uses logical connectives 𝖠 (and),
∨ (or) and ┓ (not).
o It uses Existential (∃) and Universal Quantifiers (∀) to bind the variable.
Notation:
Where
For example:
Output: This query will yield the article, page, and subject from the relational javatpoint, where the subject is a
database.
3) Avg()
4) Min()
5) Max()
1 A 80
2 B 40
3 C 60
4 D 70
5 E 60
6 F Null
Count():
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():
Min():
Min(salary): Minimum value in the salary column except NULL i.e., 40.
Max(salary): Maximum value in the salary i.e., 80.
A relational database collects different types of data sets that use tables, records, and columns. It is used to
create a well-defined relationship between database tables so that relational databases can be easily stored. For
example of relational databases such as Microsoft SQL Server, Oracle Database, MYSQL, etc.
Keep Watching
One to One Relationship (1:1): It is used to create a relationship between two tables in which a single row of
the first table can only be related to one and only one records of a second table. Similarly, the row of a second
table can also be related to anyone row of the first table.
Many to Many Relationship: It is many to many relationships that create a relationship between two tables.
Each record of the first table can relate to any records (or no records) in the second table. Similarly, each record
of the second table can also relate to more than one record of the first table. It is also represented
an N:N relationship.
For example, there are many people involved in each project, and every person can involve more than one
project.
o A table is in BCNF if every functional dependency X → Y, X is the super key of the table.
o For BCNF, the table should be in 3NF, and for every FD, LHS is super key.
Example: Let's assume there is a company where employees work in more than one department.
EMPLOYEE table:
1 . EMP_ID → EMP_COUNTRY
2 . EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}
The table is not in BCNF because neither EMP_DEPT nor EMP_ID alone are keys.
To convert the given table into BCNF, we decompose it into three tables:
EMP_COUNTRY table:
EMP_ID EMP_COUNTRY
264 India
264 India
EMP_DEPT table:
EMP_DEPT_MAPPING table:
EMP_ID EMP_DEPT
D394 283
D394 300
D283 232
D283 549
Functional dependencies:
. EMP_ID → EMP_COUNTRY
1
. EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}
2
Candidate keys:
Normalization
If a database design is not perfect, it may contain anomalies, which are like a bad dream for any database
administrator. Managing a database with anomalies is next to impossible.
Update anomalies − If data items are scattered and are not linked to each other properly, then it could
lead to strange situations. For example, when we try to update one data item having its copies scattered
over several places, a few instances get updated properly while a few others are left with old values.
Such instances leave the database in an inconsistent state.
Deletion anomalies − We tried to delete a record, but parts of it was left undeleted because of
unawareness, the data is also saved somewhere else.
Insert anomalies − We tried to insert data in a record that does not exist at all.
Normalization is a method to remove all these anomalies and bring the database to a consistent state.
First Normal Form is defined in the definition of relations (tables) itself. This rule defines that all the attributes
in a relation must have atomic domains. The values in an atomic domain are indivisible units.
Each attribute must contain only a single value from its pre-defined domain.
Before we learn about the second normal form, we need to understand the following −
Prime attribute − An attribute, which is a part of the candidate-key, is known as a prime attribute.
Non-prime attribute − An attribute, which is not a part of the prime-key, is said to be a non-prime
attribute.
If we follow second normal form, then every non-prime attribute should be fully functionally dependent on
prime key attribute. That is, if X → A holds, then there should not be any proper subset Y of X, for which Y
→ A also holds true.
We see here in Student_Project relation that the prime key attributes are Stu_ID and Proj_ID. According to the
rule, non-key attributes, i.e. Stu_Name and Proj_Name must be dependent upon both and not on any of the
prime key attribute individually. But we find that Stu_Name can be identified by Stu_ID and Proj_Name can
be identified by Proj_ID independently. This is called partial dependency, which is not allowed in Second
Normal Form.
We broke the relation in two as depicted in the above picture. So there exists no partial dependency.
For a relation to be in Third Normal Form, it must be in Second Normal form and the following must satisfy −
We find that in the above Student_detail relation, Stu_ID is the key and only prime key attribute. We find that
City can be identified by Stu_ID as well as Zip itself. Neither Zip is a superkey nor is City a prime attribute.
Additionally, Stu_ID → Zip → City, so there exists transitive dependency.
To bring this relation into third normal form, we break the relation into two relations as follows −
Boyce-Codd Normal Form (BCNF) is an extension of Third Normal Form on strict terms. BCNF states that −
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
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 how these records are stored in a HDAM or HIDAM database.
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.
Comments in SQL
There are two ways in which you can comment in SQL, i.e. either the Single-Line Comments or the Multi-Line
Comments.
Single-Line Comments
The single line comment starts with two hyphens (–). So, any text mentioned after (–), till the end of a single
line will be ignored by the compiler.
Example:
1 --Select all:
Multi-Line Comments
The Multi-line comments start with /* and end with */. So, any text mentioned between /* and */ will be
ignored by the compiler.
Example:
1 /*Select all the columns
This section of the article will give you an insight into the commands through which you can define your
database. The commands are as follows:
CREATE
DROP
TRUNCATE
ALTER
BACKUP DATABASE
CREATE
This statement is used to create a table or a database.
Syntax
CREATE DATABASE DatabaseName;
Example
1 CREATE DATABASE Employee;
Syntax
CREATE TABLE TableName (
Column1 datatype,
Column2 datatype,
Column3 datatype,
....
ColumnN datatype
);
Example
1 CREATE TABLE Employee_Info
2 (
3 EmployeeID int,
4 EmployeeName varchar(255),
5 Emergency ContactName
7 Address
8 varchar(255), City
9 varchar(255),
10 Country varchar(255)
);
You can also create a table using another table. Refer the below sytax and example:
3 FROM Employee_Info;
DROP
This statement is used to drop an existing table or a database.
Syntax
DROP DATABASE DatabaseName;
Example
1 DROP DATABASE Employee;
Syntax
DROP TABLE TableName;
Example
1 DROP Table Employee_Info;
TRUNCATE
This command is used to delete the information present in the table but does not delete the table. So, once you
use this command, your information will be lost, but not the table.
Syntax
TRUNCATE TABLE TableName;
Example
1 TRUNCATE Table Employee_Info;
ALTER
This command is used to delete, modify or add constraints or columns in an existing table.
Syntax
ALTER TABLE TableName
ADD ColumnName Datatype;
3 ALTER TABLE
4 Employee_Info ADD
5 BloodGroup varchar(255);
9 ALTER TABLE
Employee_Info DROP
COLUMN BloodGroup ;
The ‘ALTER TABLE’ Statement with ALTER/MODIFY COLUMN
This statement is used to change the datatype of an existing column in a table.
Syntax
ALTER TABLE TableName
ALTER COLUMN ColumnName Datatype;
Example
1 --Add a column DOB and change the data type to Date.
Syntax
BACKUP DATABASE DatabaseName
TO DISK = 'filepath';
Example
1 BACKUP DATABASE Employee
2 TO DISK = 'C:UsersSahitiDesktop';
You can also use a differential back up. This type of back up only backs up the parts of the database,
which have changed since the last complete backup of the database.
Syntax
BACKUP DATABASE DatabaseName
TO DISK = 'filepath'
WITH DIFFERENTIAL;
Example
1 BACKUP DATABASE Employee
2 TO DISK = 'C:UsersSahitiDesktop'
3 WITH DIFFERENTIAL;