Database Management System
Database Management System
KHULNA
An assignment on,
Submitted to :
Submitted by :
Salman Ahmed
Roll : 1709050
PostgreSQL
MySQL
Microsoft Access
SQLite
Mainly a DBMS manipulates the data itself, the data format, field names, record structure and
file structure. It defines rules to validate and manipulate the data. DBMS are set up on specific
data handling concepts, as the practice of administrating a database evolves. The earliest
databases only handled individual single pieces of specially formatted data. Today’s more
evolved systems can handle different kinds of less formatted data and tie them together in more
elaborate ways.
Relational database
Hierarchical database
Network database
Object-oriented database
Relational Database
The first thing to know is that database which we deal with the most, like SQL, is based
upon Relational Databases. The easiest way to put relational databases is: They store data in
form of tables which are related to each other.
For a further understanding, the relational database model works on the concept of storing data
where data is represented by tuples, grouped into relations. It may occur to you what are tuples,
so let’s look at what exactly are tuples:
So, we may see that storing the data in form of a table, we have two major attributes, rows and
columns.
As you can see in the example below which show the relational database for a library.
In this example, the two tables are connected by the Book No, which acts as a key between the
two tables. Here you can see the two tables are related to each other or share a relation defined
using Book No.
Each table is related to a certain type of data and thus a table relates all the various data types
present inside it. Each data type actually defines a certain new column and thus a new property
is given to the table. The table relates or combines all the columns present in the table to each
other and thus the data too. This leads to the fact that certain times tables are termed
as “relations” also.
Hierarchical Database
The Hierarchical databases are actually databases which follow a tree-like structure. Just
imagine a family hierarchy tree, maybe of an Ameoba-like family, i.e., one parent dividing into
multiple children. It may look like the picture below:
Network Database
Network databases are similar to Hierarchical ones, the only difference is one child is connected
to many parents. Just take a look at the example of an E-Commerce company, where the
children, Seller, and Customer both share common child Product.
Object-oriented Database
We saw that RDBMS actually stores values in form of tables, but what if we make a separate
table for each book? This is what Object-Oriented Database is:
What are the differences between database and database management system?
In a database
Besides computers, databases management system
can even be maintained in (DBMS), all the records
1 physical ledgers, books or are maintained only on a
. Storage papers. computer.
As a computer system is
As databases can be handled involved in a database
manually or via computers, when management system, the
3 SQL is not used to retrieve retrieval of information is
. Speed information, it can be very slow. very quick.
In the database
management system
(DBMS), a lot of
information can be
In case of the databases, very changed at one time (as it
5 Data less information can be modified can have many users
. Manipulation at a time. using it at the same time).
The database
management system
(DBMS) ensures that the
The databases do not ensure data will always be
6 Backup and that the data will be available available even after
. Recovery after failure arises. system failures.
A database is typically designed so that it is easy to store and access information. A good
database is much needed to any company or organization. This is because the database stores
all the pertinent details about the company such as employee records, transactional records,
salary details etc. The various reasons a database is important are −
In traditional file systems, we cannot store data in the form of objects. In practical-world
applications, data is stored in objects and not files. So in a file system, some application
software maps the data stored in files to objects so that can be used further.
We can directly store data in the form of objects in a database management system. Application
level code needs to be written to handle, store and scan through the data in a file system
whereas a DBMS gives us the ability to query the database.
DBMS makes complex memory management easy to handle. In file systems, files are indexed
in place of objects so query operations require entire file scans whereas in a DBMS , object
indexing takes place efficiently through database schema based on any attribute of the data or a
data-property. This helps in fast retrieval of data based on the indexed attribute.
Several applications allow user to simultaneously access data. This may lead to inconsistency
in data in case files are used. A DBMS provides mechanisms to deal with this kind of data
inconsistency while allowing users to access data concurrently. A DBMS
implements ACID(atomicity, durability, isolation, consistency) properties to ensure efficient
transaction management without data corruption.
A DBMS can grant access to various users and determine which part and how much of the data
can they access from the database thus removing redundancy. Otherwise in file system,
separate files have to be created for each user containing the amount of data that they can
access. Moreover, if a user has to extract specific data, then he needs a code/application to
process that task in case of file system, e.g. Suppose a manager needs a list of all employees
having salary greater than X. Then we need to write business logic for the same in case data is
stored in files. In case of DBMS, it provides easy access of data through queries,
(e.g., SELECT queries) and whole logic need not be rewritten. Users can specify exactly what
they want to extract out of the data.
6) Integrity constraints:
Data stored in databases must satisfy integrity constraints. For example, Consider a database
schema consisting of the various educational programs offered by a university such
as(B.Tech/M.Tech/B.Sc/M.Sc/BCA/MCA) etc. Then we have a schema of students enrolled in
these programs. A DBMS ensures that it is only out of one of the programs offered schema ,
that the student is enrolled in, i.e. Not anything out of the blue. Hence, database integrity is
preserved.
We can modify a database by inserting or updating or deleting a data from the database.
Insertion: To insert data into a relation, we either specify a tuple to be inserted or write a query
whose result is a set of tuples to be inserted. Obviously, the attribute values for inserted tuples
must be members of the corresponding attribute’s domain. Similarly, tuples inserted must have
the correct number of attributes.
Deletion: A delete request is expressed in much the same way as a query. We can delete only
whole tuples; we cannot delete values on only particular attributes. Note that a delete
command operates on only one relation. If we want to delete tuples from several relations, we
must use one delete command for each relation.
Updates: In certain situations, we may wish to change a value in a tuple without changing all
values in the tuple. For this purpose, the update statement can be used. As we could for insert
and delete, we can choose the tuples to be updated by using a query. In general, the where
clause of the update statement may contain any construct legal in the where clause of the select
statement (including nested selects). As with insert and delete, a nested select within an update
statement may reference the relation that is being updated.
There are mainly seven different types of Keys in DBMS and each key has it’s different
functionality:
Super Key - A super key is a group of single or multiple keys which identifies rows in a
table.
Primary Key - is a column or group of columns in a table that uniquely identify every
row in that table.
Candidate Key - is a set of attributes that uniquely identify tuples in a table. Candidate
Key is a super key with no repeated attributes.
Alternate Key - is a column or group of columns in a table that uniquely identify every
row in that table.
Foreign Key - is a column that creates a relationship between two tables. The purpose
of Foreign keys is to maintain data integrity and allow navigation between two different
instances of an entity.
Compound Key - has two or more attributes that allow you to uniquely recognize a
specific record. It is possible that each column may not be unique by itself within the
database.
Composite Key - An artificial key which aims to uniquely identify each record is called a
surrogate key. These kind of key are unique because they are created when you don't
have any natural primary key.
Surrogate Key - An artificial key which aims to uniquely identify each record is called a
surrogate key. These kind of key are unique because they are created when you don't
have any natural primary key.
A super key is a group of single or multiple keys which identifies rows in a table. A Super key
may have additional attributes that are not needed for unique identification.
Example:
In the above-given example, Student ID and Roll number name are super keys.
The value in a primary key column can never be modified or updated if any foreign key
refers to that primary key.
Example:
CANDIDATE KEY is a set of attributes that uniquely identify tuples in a table. Candidate Key is
a super key with no repeated attributes. The Primary key should be selected from the candidate
keys. Every table must have at least a single candidate key. A table can have multiple candidate
keys but only a single primary key.
FOREIGN KEY is a column that creates a relationship between two tables. The purpose of
Foreign keys is to maintain data integrity and allow navigation between two different instances
of an entity. It acts as a cross-reference between two tables as it references the primary key of
another table.
Example:
DeptCode DeptName
001 Science
002 English
005 Computer
In this key in DBMS example, we have two table, teach and department in a school. However,
there is no way to see which search work in which department.
In this table, adding the foreign key in Deptcode to the Teacher name, we can create a
relationship between the two tables.
ALTERNATE KEYS is a column or group of columns in a table that uniquely identify every row
in that table. A table can have multiple choices for a primary key but only one can be set as the
primary key. All the keys which are not primary key are called an Alternate Key.
Example:
In this table, StudID, Roll No, Email are qualified to become a primary key. But since StudID is
the primary key, Roll No, Email becomes the alternative key.
Functional Dependency (FD) is a constraint that determines the relation of one attribute to
another attribute in a Database Management System (DBMS). Functional Dependency helps to
maintain the quality of data in the database. It plays a vital role to find the difference between
good and bad database design.
Example:
In this example, if we know the value of Employee number, we can obtain Employee Name, city,
salary, etc. By this, we can say that the city, Employee Name, and salary are functionally
depended on Employee number.
Below are the Three most important rules for Functional Dependency in Database:
Augmentation rule: When x -> y holds, and c is attribute set, then ac -> bc also holds.
That is adding attributes which do not change the basic dependencies.
Transitivity rule: This rule is very much similar to the transitive rule in algebra if x -> y
holds and y -> z holds, then x -> z also holds. X -> y is called as functionally that
determines y.
There are mainly four types of Functional Dependency in DBMS. Following are the types of
Functional Dependencies in DBMS:
Multi-valued Dependency
Trivial Functional Dependency
Non-Trivial Functional Dependency
Transitive Dependency
In Multivalued functional dependency, entities of the dependent set are not dependent on each
other.
i.e. If a → {b, c} and there exists no functional dependency between b and c, then it is called
a multivalued functional dependency.
For example,
42 abc 17the
43 pqr 18
44 xyz 18
45 abc 19
For example,
Nam
Roll_no e Age
42 abc 17
43 pqr 18
44 xyz 18
In Non-trivial functional dependency, the dependent is strictly not a subset of the determinant.
i.e. If X → Y and Y is not a subset of X, then it is called Non-trivial functional dependency.
For example,
Roll_n
o Name Age
42 abc 17
43 pqr 18
44 xyz 18
42 abc CO 4
43 pqr EC 2
44 xyz IT 1
45 abc EC 2
1. It avoids data redundancy. Therefore, same data do not repeat at multiple locations in that database.
4. It helps to identify bad designs. 5. It helps to find facts regarding the database design.
Armstrong’s Axioms rule : If F is a set of functional dependencies then the closure of F, denoted as F+ ,
is the set of all functional dependencies logically implied by F. Armstrong's Axioms are a set of rules, that
when applied repeatedly, generates a closure of functional dependencies.
• Reflexive rule − If alpha is a set of attributes and beta is a subset of alpha, then alpha holds beta.
• Augmentation rule − If a → b holds and y is attribute set, then ay → by also holds. That is adding
attributes in dependencies, does not change the basic dependencies.
• Transitivity rule − Same as transitive rule in algebra, if a → b holds and b → c holds, then a → c also
holds. a → b is called as a functionally that determines b.
What is Normalization?
Normalization is a database design technique that reduces data redundancy and eliminates
undesirable characteristics like insertion, update and deletion anomalies. Normalization rules
divides larger tables into smaller tables and links them using relationships. The purpose of
normalization in SQL is to eliminate redundant data and ensure data is stored logically.
Such as:
1. 1NF
2. 2NF
3. 3NF
4. BCNF
5. 4NF
6. 5NF.
1. First Normal Form(1NF)
The table or relation is said to be in First Normal Form if it does not contain any multi-valued or
composite attributes. So the table or relation should contain only single-valued attributes for
fulfilling the condition for First Normal Form.
32 Zack Geography
The above table is not in First Normal Form as this contains the multi-valued attribute. The
below table is transformed into the First Normal Form as it contains only atomic values.
19 Rajesh Math
19 Rajesh Science
23 Supriya History
23 Supriya English
32 Zack Geography
19 Rajesh Math
19 Rajesh Science
23 Supriya History
23 Supriya English
32 Zack Geography
The above table needs to be broken into two tables as below to make it Second Normal Form
compliant.
STUDENT
Roll Name
19 Rajesh
23 Supriya
32 Zack
SUBJECT_DETAIL
Roll Subject
19 Math
19 Science
23 History
23 English
32 Geography
The functional dependency from the table ‘STUDENT’ is removed and the column Subject in
‘SUBJECT_DETAIL’ is fully dependent on the primary key ‘Roll’.
A table is in Third Normal Form if it is in Second Normal Form and there should not be any
transitive dependency for the non-prime attributes.
So for every non-trivial functional dependency A->B, if any of the two conditions is true from the
below, the relation is said to be in Third Normal Form.
1. A is a super key.
The candidate key in the above table is EMP_ID and the functional dependency set is EMP_ID-
>EMP_NAME, EMP_ID->EMP_DEPT, EMP_ID->EMP_STATE, EMP_STATE ->
EMP_COUNTRY. The EMP_COUNTRY is transitively dependent upon EMP_STATE. So we
need to break the above table to two tables as below for transforming it to the Third Normal
Form.
EMPLOYEE:
STATE_COUNTRY:
Florida U.S.
Maharashtra India
Texas U.S.
The EMP_STATE becomes the primary key in the above table and the transitive dependency is
removed.
4. Boyce-Codd Normal Form(BCNF)
For a table to be in Boyce-Codd Normal Form, it should be in Third Normal Form and for every
functional dependency A->B, A is the super key in the table.
EMP_DEPT table:
The functional dependency for the above table is: ID -> COUNTRY, DEPARTMENT ->
{DEPT_TYPE, DEPT_NO}. {ID, DEPARTMENT} is the candidate key. To transform the above
table to BCNF, we have to break it into three tables as below:
EMP_COUNTRY:
ID COUNTRY
9890 India
11090 US
12390 India
DEPT_DETAILS:
DEPARTMENT DEPT_TYPE DEPT_NO
EMP_DEPARTMENT_MAP:
ID DEPARTMENT
9890 Marketing
11090 Finance
12390 Sales
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.
Let us consider a table with student id, student name, student address and subject opted.
1. Updating Anomaly: To update address of a student who occurs twice or more than twice
in a table, we will have to update student address column in all the rows, else data will become
inconsistent.
2. Insertion Anomaly: Let us consider for a new admission, we have a student id, name and
address of a student but if student has not opted for any subjects yes then we have to insert null
there, leading to insertion anomaly.
3. Deletion Anomaly: If one student id has only one subject and temporarily he drops it,
when we delete that row, entire student record will be deleted along with it.
1. Lossless Decomposition
o If the information is not lost from the relation that is decomposed, then the
decomposition will be lossless.
o The lossless decomposition guarantees that the join of relations will result in the same
relation as it was decomposed.
o The relation is said to be lossless decomposition if natural joins of all the decomposition
give the original relation.
2. Dependency Preserving
o In the dependency preservation, at least one decomposed table must satisfy every
dependency.
o If a relation R is decomposed into relation R1 and R2, then the dependencies of R either
must be a part of R1 or R2 or must be derivable from the combination of functional
dependencies of R1 and R2.
o For example, suppose there is a relation R (A, B, C, D) with functional dependency set
(A->BC). The relational R is decomposed into R1(ABC) and R2(AD) which is
dependency preserving because FD A->BC is a part of relation R1(ABC).
1. Functional decomposition breaks down a large, complex process into an array of similar,
simpler units or tasks, fostering better understanding of the overall process.
2. A functional decomposition diagram contains the whole function or project along with all of
the necessary sub- tasks needed to complete it.
3. Functional decomposition is a problem solving tool used in several contexts, from business
and industry to computer programming.
What is the algorithm to test whether a functional decomposition is loss-less or
not?
Then,
Condition 01:
Union of both the sub relations must contain all the attributes that are present in the original
relation R.
Thus, R1 ∪ R2 = R
Condition 02:
Thus, R1 ∩ R2 ≠ ∅
Condition 03:
Intersection of both the sub relations must be a super key of either R1 or R2 or both.
A database schema represents the logical configuration of all or part of a relational database. It
can exist both as a visual representation and as a set of formulas known as integrity constraints
that govern a database. These formulas are expressed in a data definition language, such as
SQL. As part of a data dictionary, a database schema indicates how the entities that make up
the database relate to one another, including tables, views, stored procedures, and more.
There are two main kinds of database schema:
1. A logical database schema conveys the logical constraints that apply to the stored data. It
may define integrity constraints, views, and tables.
2. A physical database schema lays out how data is stored physically on a storage system in
terms of files and indices.
A database schema is used to outline the architecture of a database, and it will help ensure the
following:
A schema is the outline of a database. It is represented in a graphic format, like our example
from earlier. Schemas do not contain any data.One way to think about a schema is that it is a
blueprint for a database. The database hasn’t been built yet—or is still being built—and the
blueprint guides the development team in creating the database.
A database instance is a hosted version of a database. For instance, the Career Karma blog
has a database instance that stores all of our posts, such as this article. Database instances
can change over time as their contents change, whereas database schemas usually remain the
same.
With that said, a database schema may be updated as new features are requested for a
software project. Making changes to a schema typically involves the work of both developers
and database administrators. Developers will produce the requirements for a change to a
database, and database administrators will implement those changes.
What is Data Model?
Explain it and it’s variations. Data Model is the modeling of the data description, data semantics,
and consistency constraints of the data. It provides the conceptual tools for describing the
design of a database at each level of data abstraction. There are four types of data models.
1. Relational Data Model: This type of model designs the data in the form of rows
and columns within a table. Thus, a relational model uses tables for representing
data and in-between relationships. Tables are also called relations. This type of
model designs the data in the form of rows and columns within a table. Thus, a
relational model uses tables for representing data and in-between relationships.
Tables are also called relations.
4. Semi-structured Data Models: This type of data model is different from the
other three data models. The semi-structured data model allows the data
specifications at places where the individual data items of the same type may
have different attributes sets. The Extensible Markup Language, also known as
XML, is widely used for representing the semi-structured data. Although XML
was initially designed for including the markup information to the text document, it
gains importance because of its application in the exchange of data.
SQL is Structured Query Language, which is a computer language for storing, manipulating and
retrieving data stored in a relational database.
SQL is the standard language for Relational Database System. All the Relational Database
Management Systems (RDMS) like MySQL, MS Access, Oracle, Sybase, Informix, Postgres
and SQL Server use SQL as their standard database language.
Also, they are using different dialects, such as –
A query language is a specialized programming language for searching and changing the
contents of a database. Query language (QL) refers to any computer programming language
that requests and retrieves data from database and information systems by sending queries. It
works on user entered structured and formal programming command based queries to find and
extract data from host databases.
If we talk about normal queries we fire on the database they should be correct and in a well-
defined structure which means they should follow a proper syntax if the syntax or query is wrong
definitely we will get an error and due to that our application or calculation definitely going to
stop. So to overcome this problem QBE was introduced. QBE stands for Query by Example and
it was developed in 1970 by Moshe Zloof at IBM.
It is a graphical query language where we get a user interface and then we fill some required
fields to get our proper result.
In SQL we will get an error if the query is not correct but in the case of QBE if the query is wrong
either we get a wrong answer or the query will not be going to execute but we will never get any
error.
What are the types of Query language?
Such as:
What are the fundamental operations of relational algebra? Also describe select and
project operations.
Select operation:
The select operation is used to choose a subset of the tuples from a relation that satisfies a
selection condition. One can consider the select operation to be a filter that keeps only those
tuples that satisfy a qualifying condition. Alternatively, we can consider the select operation to
restrict the tuples in a relation to only those tuples that satisfy the condition. The select
operation can also be visualized as a horizontal partition of the relation into two sets of tuples-
those tuples that satisfy the condition and are selected, and those tuples that do notsatisfy the
condition and are discarded.
Project operation:
If we think of a relation as a table, the select operation chooses some of the rows from the table
while discarding other rows. The project operation, on the other hand, selects certain columns
from the table and discards the other columns. If we are interested in only certain attributes of a
relation, we use the project operation to project the relation over these attributes only.
Therefore, the result of the project operation can be visualized as a vertical position of the
relation into two relations: one has the needed columns, and the other contains the discarded
columns.
References
https://www.bytenap.com/what-is-a-database-why-do-we-need-it/
https://careerkarma.com/blog/database-schema/
https://www.tutorialride.com/dbms/database-decomposition.htm
https://hackr.io/blog/dbms-normalization
https://www.guru99.com/database-normalization.html
https://www.geeksforgeeks.org/types-of-functional-dependencies-in-dbms/
https://www.tutorialspoint.com/difference-between-super-key-and-candidate-key