0% found this document useful (0 votes)
15 views20 pages

Database

Uploaded by

krishna aute
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views20 pages

Database

Uploaded by

krishna aute
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Database

Name itself indicates what it is. Database is a place/container where all the data is stored. But
what is data? In a database, even a smallest piece of information becomes data. For example,
Student is a data, course is a data, and Color is a data, height, weight, food everything is data. In
short, all the living and non-living objects in this world is a data.

Why we need data?

We need data so that we can perform various actions on them. Say, we do not have any database
and we want to record what is the height and weight of a baby in a year. What we do is note it in
a piece of paper every month. At the end of the certain period or year, we would check up if
he/she is growing correctly. If some entry is wrong or irrelevant, we correct it or strike it off.
Same is done using database. We would be storing all these information in the database. If we
want to check the growth, we would be pulling the information from the database, if we need to
change any information, we can update/delete them. But all the data will be at one place -
Database.

What type of data is stored in database?

Characteristic of a good database are:

1. Should be able to store all kinds of data that exists in this real world. Since we need to
work with all kinds of data and requirements, database should be strong enough to
store all kinds of data that is present around us.
2. Should be able to relate the entities / tables in the database by means of a relation. i.e.;
any two tables should be related. Let us say, an employee works for a department. This
implies that Employee is related to a particular department. We should be able to
define such a relationship between any two entities in the database. There should not
be any table lying without any mapping.
3. Data and application should be isolated. Because database is a system which gives the
platform to store the data, and the data is the one which allows the database to work.
Hence there should be clear differentiation between them.
4. There should not be any duplication of data in the database. Data should be stored in
such a way that it should not be repeated in multiple tables. If repeated, it would be
unnecessary waste of DB space and maintaining such data becomes chaos.
5. DBMS has a strong query language. Once the database is designed, this helps the user
to retrieve and manipulate the data. If a particular user wants to see any specific data,
he can apply as many filtering conditions that he wants and pull the data that he needs.
6. Multiple users should be able to access the same database, without affecting the other
user. i.e.; if teachers want to update a student’s marks in Results table at the same time,
then they should be allowed to update the marks for their subjects, without modifying
other subject marks. A good database should support this feature.
7. It supports multiple views to the user, depending on his role. In a school database,
Students will able to see only their reports and their access would be read only. At the
same time teachers will have access to all the students with the modification rights. But
the database is the same. Hence a single database provides different views to different
users.
8. Database should also provide security, i.e.; when there are multiple users are accessing
the database, each user will have their own levels of rights to see the database. Some
of them will be allowed to see whole database, and some will have only partial rights.
For example, instructor who is teaching Physics will have access to see and update
marks of his subject. He will not have access for other subjects. But the HOD will have
full access on all the subjects.
9. Database should also support ACID property. i.e.; while performing any transactions
like insert, update and delete, database makes sure that the real purpose of the data is
not lost. For example, if a student’s address is updated, then it should make sure that
there is no duplicate data is created nor there is any data mismatch for that student.

As we now know what is a database, who would be the users of database? Of course the
developers will be using this database to design and develop. Who else? There would be an
administrator, who keeps watching the database for its usages, who is accessing it, giving access
to other users, limiting the security for the users, and any other maintenance work of the
database. And there is one more end users. These end users are the real group of people who
really uses the database and takes the advantages of database. In School database, teachers,
students are the end users, who really uses the database in their daily needs.
Where all are these database used? Everywhere!! Now a day, database is used in each and every
place. We can see the use of database in supermarkets, stock exchange, college, library, ATMs,
offices, banks, hospitals etc.

Components of a database includes

User: - Users are the one who really uses the database. Users can be administrator, developer or
the end users.

Data or Database: - As we discussed already, data is one of the important factor of database. A
very huge amount of data will be stored in the database and it forms the main source for all other
components to interact with each other. There are two types of data. One is user data. It contains
the data which is responsible for the database, i.e.; based on the requirement, the data will be
stored in the various tables of the database in the form of rows and columns. Another data is
Metadata. It is known as ‘data about data’, i.e.; it stores the information like how many tables,
their names, how many columns and their names, primary keys, foreign keys etc. basically these
metadata will have information about each tables and their constraints in the database.

DBMS: - This is the software helps the user to interact with the database. It allows the users to
insert, delete, update or retrieve the data. All these operations are handled by query languages
like MySQL, Oracle etc.

Database Application: - It the application program which helps the users to interact with the
database by means of query languages. Database application will not have any idea about the
underlying DBMS.
Structure of Database Management System (DBMS)

We saw how we can connect to database. But how is the database laid to process all user
requests? Since it is responsible to store huge amount of data and is capable of handling multiple
requests from users simultaneously, it should be arranged properly. One can imagine a database
as a brain! How is the structure of brain? Bit sophisticated and each part of the brain is
responsible for some specific tasks. Similarly, Database is also designed.

At very high level, a database is considered as shown in below diagram. Let us see them in
detail below.

● Applications: - It can be considered as a user friendly web page where the user enters
the requests. Here he simply enters the details that he needs and presses buttons to get
the data.
● End User: - They are the real users of the database. They can be developers, designers,
administrator or the actual users of the database.
● DDL: - Data Definition Language (DDL) is a query fired to create database, schema,
tables, mappings etc in the database. These are the commands used to create the
objects like tables, indexes in the database for the first time. In other words, they create
structure of the database.
● DDL Compiler: - This part of database is responsible for processing the DDL
commands. That means these compiler actually breaks down the command into
machine understandable codes. It is also responsible for storing the metadata
information like table name, space used by it, number of columns in it, mapping
information etc.
● DML Compiler: - When the user inserts, deletes, updates or retrieves the record from
the database, he will be sending request which he understands by pressing some
buttons. But for the database to work/understand the request, it should be broken down
to object code. This is done by this compiler. One can imagine this as when a person is
asked some question, how this is broken down into waves to reach the brain!
● Query Optimizer: - When user fires some request, he is least bothered how it will be
fired on the database. He is not all aware of database or its way of performance. But
whatever be the request, it should be efficient enough to fetch, insert, update or delete
the data from the database. The query optimizer decides the best way to execute the
user request which is received from the DML compiler. It is similar to selecting the
best nerve to carry the waves to brain!
● Stored Data Manager: - This is also known as Database Control System. It is one the
main central system of the database. It is responsible for various tasks
o It converts the requests received from query optimizer to machine
understandable form. It makes actual request inside the database. It is like
fetching the exact part of the brain to answer.
o It helps to maintain consistency and integrity by applying the constraints. That
means, it does not allow inserting / updating / deleting any data if it has child
entry. Similarly it does not allow entering any duplicate value into database
tables.
o It controls concurrent access. If there is multiple users accessing the database at
the same time, it makes sure, all of them see correct data. It guarantees that
there is no data loss or data mismatch happens between the transactions of
multiple users.
o It helps to backup the database and recover data whenever required. Since it is
a huge database and when there is any unexpected exploit of transaction, and
reverting the changes are not easy. It maintains the backup of all data, so that it
can be recovered.
● Data Files: - It has the real data stored in it. It can be stored as magnetic tapes,
magnetic disks or optical disks.
● Compiled DML: - Some of the processed DML statements (insert, update, delete) are
stored in it so that if there is similar requests, it will be re-used.
● Data Dictionary: - It contains all the information about the database. As the name
suggests, it is the dictionary of all the data items. It contains description of all the
tables, view, materialized views, constraints, indexes, triggers etc.
File Processing System

Introduction

In a daily life, we come across various needs to store data. It can be maintaining daily household
bills, bank account details, salary details, payment details, student information, student reports,
books in the library etc. How it will be recorded at one place, so that we can get it back when
required? It should be recorded in such a way that

1. Should be able to get the data any point in time latter


2. Should be able to add details to it whenever required
3. Should be able to modify stored information, as needed
4. Should also be able to delete them

In traditional approach, before to computer, all informations were stored in papers. When we
need information, we used to search through the papers. If we know particular date or category
of information we are searching, we go to that particular session in the papers. When we want
update or delete some data, we search for it and modify them or strike off them. If the data is
limited, then all these tasks are easy. Imagine library information or information about a student
in School, or baking system! How do we search for single required data in papers? It is a never
ending task! Yes, Computers solved our problems.

File Processing System


When computers came, all these jobs become easy. But initial days, these records were stored in
the form of files. The way we stored in files is similar to papers, in the form of flat files – to be
simpler, in notepad. Yes, the informations where all in the notepads with each fields of
information separated by space, tab comma, semicolon or any other symbol.

All the files were grouped based on their categories; file used to have only related informations
and each file is named properly. As we can see in the above sample file has Student information.
Student files for each class were bundled inside different folders to identify it quickly.

Now, if we want to see a specific Student detail from a file, what do we do? We know which file
will have the data, we open that file and search for his details. Fine, here we see the files; we can
open it and search for it. But imagine we want to display student details in a UI. Now how will
we open a file, read or update it? There different programs like C, C++, COBOL etc which helps
to do this task. Using these programming languages, we can search for files, open them, search
for the data inside them, and go to specific line in the file, add/update/delete specific information.

Disadvantages of file processing

Database Management System

To overcome all drawbacks of file processing system, a new system called database system is
developed. All the files in the file processing system are known as tables in the database. The
contents of files form records of the table. In database, each of column values are known as
attribute and each row of information is known as record. There no difference in the data being
stored. But it is different from the file system by the way data is stored and accessed in the
database.

In the database, each set of information is stored in the form of rows and columns. We define a
unique key column for each record known as primary key. Using primary key, we can access the
data much faster than file system. We can also define a mapping between any two related tables.
This helps in reducing unnecessary data storage and faster retrieval of data.

Below is the example how the data is stored in the database tables logically.

How do we access these data from the database? For this purpose, database defines a collection
of programs that allows the users to insert, delete, update and retrieve the data from the database
based on user’s requirement. These set of programs are known as database management system –
DBMS. Apart from basic transactions, it allows the users to perform complex transaction; it
helps to maintain consistency, atomicity, security, and controls concurrency. Oracle, MySQL,
SQL Servers, DB2, FoxPro, dBase etc are some of the DBMS available in the market. Though
they are manufactured by different manufacturer, basic functionalities of all them are same.

Advantages of DBMS

DBMS is developed to cover the drawbacks of the traditional file system.

1. Data Mapping and Access: - DBMS defines the way to map any two related tables by
means of primary key –foreign key relationship. Primary key is the column in the table
which responsible for uniquely identifying each record in the table. Foreign key is the
column in the table which is a primary key in other table and with which the entries in
the current table are related to other table.

For example, in the new database system, we can Student and Student_Report table as
follows.
STUDENT_ID is the unique using which we can identify each student and hence it
forms a primary key in STUDENT table. Similarly, REPORT_ID is the primary key in
the STUDENT_REPORT table. STUDENT_ID in the STUDENT_REPORT table is
the foreign key. It links STUDENT and STUDENT_REPORT tables.

Because of such mapping, it becomes each for the programmer to search for related
tables, join them, and fire the query as per the requirement. This reduces the time
consumed while searching and mapping these tables. Even when there is large amount
of data, the time consumed to retrieve, insert, update or delete is very less. Hence there
is no data isolation in the system.

Note: Mapping of tables is usually done when they are created.

2. Data Redundancy: - By the introduction of primary key in the table, data redundancy
problem is reduced to great extent. As we saw, primary key is the unique column for
each record, when there is a re-entry of same record, it does not allow saving such
records.

DBMS has strong designing techniques like normalization which makes sure the same
copy of data is not stored in same table or in multiple tables. It makes sure all the
informations are stored only once in the database tables.

We can see the difference in the way data is being stored in the file and database
system. Primary key, foreign keys are defined; unnecessary columns are removed from
the STUDENT_REPORT table in the database system. These are missing in the file
processing system.
3. Data Independence and Consistency: - DBMS defines a standard to represent the
data in the form of rows and columns. It also stores the information about the tables,
columns, keys, storage space, used space, available space etc separately from the
logical data. Hence they totally independent of the way they are stored and the data
being stored. Any changes to the physical storage (like disks, tapes etc) or structure,
does not harm the data being stored. Since DBMS defines each columns and rows at
the beginning itself and controls the way data being entered, there is no affect on the
programs or any other tables or data. Hence the consistency of the data also
maintained.

If there is a change in the address of any student, we just have to update it in the
Student table. There is no other place his information is being stored. Hence it
maintains the consistent data in the database.

Suppose there is a new column addition to STUDENT table, say DOB. This will
change the metadata to reflect additional column in the table structure. It will hardly
affect the application unless until there is a new requirement to have transaction with
DOB. Hence data independence is also assured in the database.

4. Security: - DBMS allows different levels of access to different users based on their
roles. In the school database, individual students will have access to their data alone,
while their teachers will have access to all the students whom they are teaching and for
the subjects that they are teaching. Class teacher will be able to see the reports of all
the students in that class, but not other classes.

Similarly, in a banking system, individual account holder will have Read-Only access
to their account. While accountant can update, individual account details for each of
their transaction.

All these levels of security and access are not allowed in file system.

5. Integrity: - DBMS allows having restrictions on individual columns. It would be


defined while designing the table itself. If we want to enter salary of an employee
within the range 10000 to 40000, we can impose this while designing the table by
using CHECK constraint. When salary is entered, it will automatically check for the
range specified.

CREATE TABLE EMPLOYEE ……….. CONSTRAINT chk_salary CHECK


(salary>10000 AND salary <40000)
6. Atomicity: - DBMS makes sure either the transaction is fully complete or it is rolled
back to the previous committed state. It does not allow the system to be in a partially
committed state. In our example above, DBMS commits marks change transaction
before calculating the total. If there is any crash or shutdown of the system, before
committing the marks, then updated marks will be rolled back to the original marks.
Hence it makes sure atomicity of the transaction is achieved.
7. Concurrent Access: - DBMS provide access to multiple users to access the database
at the same time. It has its own mechanism to have concurrency accesses and hence
avoid any incorrect data in the system.

Disadvantages of DBMS

1. It is bit complex. Since it supports multiple functionality to give the user the best, the
underlying software has become complex. The designers and developers should have
thorough knowledge about the software to get the most out of it.
2. Because of its complexity and functionality, it uses large amount of memory. It also
needs large memory to run efficiently.
3. DBMS system works on the centralized system, i.e.; all the users from all over the
world access this database. Hence any failure of the DBMS, will impact all the users.
4. DBMS is generalized software, i.e.; it is written work on the entire systems rather
specific one. Hence some of the application will run slow.

Architecture of Database

Database architecture can be 2-tier or 3 tier architecture based on how users are connected to the
database to get their request done. They can either directly connect to the database or their
request is received by intermediary layer, which synthesizes the request and then it sends to
database.

2-tier Architecture

In 2-tier architecture, application program directly interacts with the database. There will not be
any user interface or the user involved with database interaction. Imagine a front end application
of School, where we need to display the reports of all the students who are opted for different
subjects. In this case, the application will directly interact with the database and retreive all
required data. Here no inputs from the user are required. This involves 2-tier architecture of the
database.

Let us consider another example of two tier architecture. Consider a railway ticket reservation
system. How does this work? Imagine a person is reserving the ticket from Delhi to Goa on
particular day. At the same time another person in some other place of Delhi is also reserving the
ticket to Goa on the same day for the same train. Now there is a requirement for two tickets, but
for different persons. What will reservation system do? It takes the request from both of them,
and queues the requests entered by each of them. Here the request entered to application layer
and request is sent to database layer. Once the request is processed in database, the result is sent
back to application layer for the user.

Advantages of 2-tier Architecture

● Easy to understand as it directly communicates with the database.


● Requested data can be retrieved very quickly, when there is less number of users.
● Easy to modify – any changes required, directly requests can be sent to database
● Easy to maintain – When there are multiple requests, it will be handled in a queue and
there will not be any chaos.

Disadvantages of 2-tier architecture:

Data Independence

Database consists on different objects like schema, tables, views, constants, cursors, procedures,
functions, packages, synonyms etc. They have their specifications, tasks and value in the
database. But they all differ from what we see on the monitor. i.e.; what we see on the monitor is
the user friendly display of the data. But actual structure and data are stored in different way.
There are storage information’s about the data, object structure. There are basic information’s
about the objects like their names, columns in them, total number of records, their indexes and
constraints, mapping between the tables, functions/procedures used in packages etc. There are
exact values for each record which are shown to the user. All these information’s are different
from each other in their own way. Let us see all of them

Each data value and structure details of the database objects are stored in magnetic tapes,
magnetic disks, optical disks etc. These informations are usually the basic storage information of
any computer. This kind of informations is called physical storage information and is usually
lowest level of information’s. They are least known to any programmer. This is called physical
level of data.

The information’s like table/view names, their columns, indexes and constraints on them,
mapping between the tables are all next level of information related to database. This
information defines the structure of the objects in the database. These are all called logical levels
of data. The developer and the DBA will have the knowledge about this data.

The user will get to see only the data stored in the database. Either they will see whole data
values or any specific records. They will not have any information about how they are stored,
what kind of datatype it has, how many records it has etc. This level of abstraction is called view
level.

In a STUDENT table example, records of each student which user sees are view level of
information. Columns, their datatypes, their mapping, and constraints like primary key, foreign
key informations are the logical level of information. The actual structure of table and data are
stored in the server’s memory. This is physical level of informations.

Physical level of abstraction is the lowest level of abstraction and view level of abstraction is the
highest level of abstraction. Based on these levels of abstraction, we have two types of data
independence.

Suppose there was a change in memory size of the database servers. This will not affect the
logical structure of any of the objects in the database. They are completely independent of the
physical structure. This is called physical data independence.

Any changes to the database objects like changes to table structure, size or addition/removal of
columns from the table will not affect user views. They will see the data like before. This is
called logical data independence.
By these two types of data independence, the isolation between the physical and logical layer is
achieved. This helps in reducing the time and cost acquired by changes in any one level in the
database. Hence, the main purpose of database to provide abstract view of data is achieved.

Workers behind the Scene

In addition to those who design, use, and administer a database, others are associated with the
design, development, and operation of the DBMS software and system environment. These
persons are typically not interested in the database content itself. We call them the workers
behind the scene, and they include the following categories:

DBMS system designers and implementers design and implement the DBMS modules and
interfaces as a software package. A DBMS is a very com-plex software system that consists of
many components, ormodules, including modules for implementing the catalog, query language
processing, interface processing, accessing and buffering data, controlling concurrency, and
handling data recovery and security. The DBMS must interface with other system software such
as the operating system and compilers for various programming languages.
Tool developers design and implement tools—the software packages that facilitate
database modeling and design, database system design, and improved performance. Tools are
optional packages that are often purchased separately. They include packages for database
design, performance monitoring, natural language or graphical interfaces, prototyping,
simulation, and test data generation. In many cases, independent software vendors develop and
market these tools.
Operators and maintenance personnel (system administration personnel) are
responsible for the actual running and maintenance of the hardware and software environment
for the database system.

Although these categories of workers behind the scene are instrumental in making the database
system available to end users, they typically do not use the database contents for their own
purposes.

View of Data in DBMS


BY CHAITANYA SINGH | FILED UNDER: DBMS

Abstraction is one of the main features of database systems. Hiding irrelevant details
from user and providing abstract view of data to users, helps in easy and
efficient user-database interaction.

To understand the view of data, you must have a basic knowledge of data abstraction
and instance & schema. Refer these two tutorials to learn them in detail.

1. Data abstraction
2. Instance and schema

What is an instance of a database?


Imagine a database with EMPLOYEE and DEPARTMENT tables. Each of the table will have their
own set of records. As there is addition of new employee, new employee record will be inserted into
the table. When an employee moves out from the department his records will be updated or deleted.

Similarly if there are any changes to the department, the respective details will be modified or
deleted. Any new department details will be added to the DEPARTMENT table.

What does this infer?

Any point in time, there is a continuous change to the records in the database objects. There will be
either increase or decrease in the number of records or there will be changes in the existing data.
Any particular point in time, there would be one particular set of records exists in each of the objects,
satisfying all the conditions of a database.
This is called an instance of a database. i.e.; at any particular point in time, what is the state of
database with data values in its object is called database instance. It changes from time to time.

Look at below snapshot of the database objects. It has EMPLOYEE and DEPARTMENT tables with
their own set of data. It shows different values of object at different time. Each set of
EMPLOYEE-DEPARTMENT data set represents instances of the database. Below are 3 instances
of the database.

Data Abstraction in DBMS


BY CHAITANYA SINGH | FILED UNDER: DBMS

Database systems are made-up of complex data structures. To ease the user
interaction with database, the developers hide internal irrelevant details from users.
This process of hiding irrelevant details from user is called data abstraction.
We have three levels of abstraction:
Physical level: This is the lowest level of data abstraction. It describes how data is
actually stored in database. You can get the complex data structure details at this
level.

Logical level: This is the middle level of 3-level data abstraction architecture. It
describes what data is stored in database.

View level: Highest level of data abstraction. This level describes the user interaction
with database system.

Example: Let’s say we are storing customer information in a customer table.


At physical level these records can be described as blocks of storage (bytes,
gigabytes, terabytes etc.) in memory. These details are often hidden from the
programmers.
At the logical level these records can be described as fields and attributes along with
their data types, their relationship among each other can be logically implemented.
The programmers generally work at this level because they are aware of such things
about database systems.

At view level, user just interact with system with the help of GUI and enter the
details at the screen, they are not aware of how the data is stored and what data is
stored; such details are hidden from them.

Instance and schema in DBMS


BY CHAITANYA SINGH | FILED UNDER: DBMS

Definition of schema: Design of a database is called the schema. Schema is of three


types: Physical schema, logical schema and view schema.

The design of a database at physical level is called physical schema, how the data
stored in blocks of storage is described at this level.

Design of database at logical level is called logical schema, programmers and


database administrators work at this level, at this level data can be described as
certain types of data records gets stored in data structures, however the internal
details such as implementation of data structure is hidden at this level (available at
physical level).

Design of database at view level is called view schema. This generally describes end
user interaction with database systems.

To learn more about these schemas, refer 3 level data abstract++ion architecture.

Definition of instance: The data stored in database at a particular moment of time is


called instance of database. Database schema defines the variable declarations in
tables that belong to a particular database; the value of these variables at a moment
of time is called the instance of that database.
Type of Database System
BY DINESH THAKUR

You might also like