UNIT 1 Database Management System DBMS 2
UNIT 1 Database Management System DBMS 2
com
Computer Science
Grade: XII
Reference Note
1. What is Database and DBMS? List out the advantages and disadvantages of
DBMS.
2. Explain the different models of DBMS with advantages and disadvantages.
3. Write differentiate between centralized and distributed database system.
4. Who is DBA? What are the major responsibilities of DBA?
5. What is normalization? Explain normalization process with examples.
6. Define the following terms. a) Data Dictionary b) Primary Key c)
Relationship d) DML
e) SQL f) Data Integrity g) DDL h) Data Security
i) Database System
Information:
When data are processed using a database program or software, they are converted to the meaningful
result, called information. Information provides answers to "who", "what", "where", and "when"
questions. Examples, Hari lives in Bharatpur-11, Chitwan.
Data Processing
Database System:
A database system consists of a collection of interrelated data and a set of application programs to access,
update and manage the data.
Database:
It is organized form of record about some person, organization or something store under certain media.
It is a collection of related information about a subject organized in a useful manner that provides a base
or foundation for procedure, such as retrieving information, drawing conclusion and make decision.
Advantage of database over flat file or file based system
1. Reduction of data redundancies
2. Shared data
3. Data independent
4. Improved integrity
5. Efficient data access
6. Multiple user interface
7. Improved security
8. Improved backup and recovery
9. Supports for concurrent transactions
10. Unforeseen queries can be answered
DBMS:
Database Management System is software that manages the data stored in a database. This is a collection
of software which is used to store data, records, process them and obtain desired information. Since, data
are very important to the end users, we must have a good way of managing data.
A DBMS is a collection of programs that manages the database structure and controls access to the data
stored in the database. The DBMS make it possible to share the data in the database among multiple
applications or users. The DBMS stands between the database and the user.
Examples: MS-Access, Oracle, FoxPro, dBase, SQL server, MySQL, Delphi, Sybase, etc.
API
APP
Database
API Management System
(DBMS) Database (DB)
User
API
APP
Disadvantages of DBMS
1. Expensive
2. Changing Technology
3. Needs Technical Training
4. Backup is needed
Field/ Attribute:
A field is a piece of information about an element. A field is represented by a column. Every field has got
a title called the field title.
Record (Tuple):
A record is information about an element such as a person, student, an employee, client, etc. A record
can have much information in different heading or titles.
Table:
A table is the arrangements of rows and columns. Each table must have unique name and must be simple.
It is the place where data and information are stored.
Keys of DBMS:
Key is a field that uniquely identifies the records, tables or data. Key in a table allows us to establish the
relation between multiple tables. Keys are also useful for finding the unique records or combination of
records from a large database tables.
Primary Key: A primary key is one or more columns in a table used to uniquely identify each row
in the table. Primary key cannot contain Null value.
A primary key is a special relational database table column (or combination of columns)
designated to uniquely identify each table record. A table cannot have more than one primary
key.
A primary key’s main features are:
It must contain a unique value under the field.
It cannot contain null values.
Every row must have a primary key value.
Foreign Key: Foreign keys represent relationships between tables. A foreign key is a column whose
values are derived from the primary key of some other table.
Candidate Key: If a relational schema has more than one key, that is called a candidate key. All
the keys which satisfy the condition of primary key can be candidate key. There can be any number
of candidate keys that can be used in place of the primary key if required.
Alternate Key/ Secondary Key: Alternative keys are those candidate keys which are not the
primary key. There can be only one primary key for a table. Therefore all the remaining candidate
keys are known as alternative.
Compound Key: It has two or more attributes that allow you to uniquely recognize specific record.
It is possible that each column may not be unique by itself within the database.
1. DDL (Data Definition Language): DDL is used by the database designers and programmers to
specify the content and structure of the table. It is used to define the physical characteristics of
records. It includes commands that manipulate the structure of objects such as views, tables, and
indexes, etc.
» CREATE: Create is used to create the database or its objects (like table, index, function, views, store
procedure and triggers).
» DROP: Drop is used to delete objects from the database.
» ALTER: Alter is used to alter the structure of the database.
» TRUNCATE: Truncate is used to remove all records from a table, including all spaces allocated for the
records are removed.
» COMMENT: Comment is used to add comments to the data dictionary.
» RENAME: Rename is used to rename an object existing in the database.
2. DML (Data Manipulation Language): DML is related with manipulation of records such as
retrieval, sorting, display and deletion of records of data. It helps user to use query and display reports
of the table. So it provides technique for processing the database.
3. DCL (Data Control Language): DCL provides additional features for security of table or database.
It includes commands for controlling data and access to the database. Examples of these commands
are commit, Rollback, Grant etc.
Database Model:
A Database model defines the logical design and structure of a database and are used to show how data
will be stored, accessed and updated in a Database Management System. It refers to the layout of a
database and helps in designing a database. The various types of database models are
Different database models
1. Hierarchical database model: this is one of the oldest types of database models. In this model
data is represented in the form of records. Each record has multiple fields. All records are arranged
in database as tree like structure. The relationship between the records is called parent child
relationship in which any child record relates to only a single parent type record.
Gurukul College
Advantages
It is the easiest model.
Searching is fast and easy if parent is known.
It is very efficient in handling one to one and one to many relationships.
Website: www.bkbhusal.com.np 7 YouTube Channel: www.youtube.com/BkBhusalEduZone
Computer Science Reference Note for Grade-XII E-mail ID: bkbhusalinfo@gmail.com
Disadvantages
It is old and outdated database model.
It does not support many to many relationships.
It increases redundancy because same data is to be repeated in different places.
2. Network database model: It replaced hierarchical network database model due to some
limitations on the model. Suppose, if an employee relates to two departments, then the
hierarchical database model cannot able to arrange records in proper place. So network, database
model was emerged to arranged non-hierarchical database. The structure of database is more like
graph rather than tree structure. A network database model is a database model that allows
multiple records to be linked the same owner file. The network model allows each child to have
multiple parents.
Gurukul College
Advantages
It accepts many to many relationships, so it is more flexible.
The searching is faster because of multidirectional pointer.
The network model is simple and easy to design.
It reduces the redundancy.
Disadvantages
It is difficult to handle the relationship in complex programs.
There is less security because of sharing data.
It increases the processing overhead due to the complex relationship.
3. Relational database model: in this model, the data is organized into tables which contain multiple
rows and columns. These tables are called relations. A row in a table represents a relationship
among a set of values. Since a table is a collection of such relationships, it is generally referred to
the mathematical term relation, from which the relational database model derives its name.
We notice from below table, here each student has a unique roll number and has marks of subject.
Here Roll makes relation between these two tables.
Table: Subject
Roll Name Math English Computer
1 Hari 80 90 95
2 Sita 90 80 85
3 Ram 95 95 95
Advantages
The breaking of complex database table into simple database table becomes possible.
Database processing is faster than other model.
There is very less redundancy.
The integrity rules can easily be implemented.
Disadvantages
It is more complex than other models.
There are too many rules because of complex relationships.
It needs more powerful computers and data storage devices.
4. Object oriented database model: In the object-oriented model, both data and their relationships
are contained in a single structure known as an object. An Object-Oriented Model reflects a very
different way to define and use entities. An object includes information about relationships
between the facts within the object, as well as information about its relationships with other
objects. An objects include data, various types of relationships, and operational procedures, the
object becomes self-contained, thus making the object-at least potentially-a basic building block
for autonomous structures.
Advantages
Semantic content is added.
Visual representation includes semantic content.
Inheritance promotes data integrity.
Disadvantages
Slow development of standards caused vendors to supply their own enhancements, thus
eliminating a widely accepted standard.
It is a complex navigational system.
There is a steep learning curve.
High system overhead slows transactions.
Pname
CName
CAddress
PAddress
College H Principal
a
Pcontact
Phone No.
Fig. E-R diagram for relation between college and principal
2. One to many: If one instance of one entity is related with many instances of other entity then
it is called the one to many relationship.
College------------------students
Bank --------------------- Employers
3. Many to many: If many instances of the one entity are related with many instances of another
entity then it is called many to many relationship.
Teachers -----------------students
Books --------------------Readers
Employers --------------Customers
Concept of Normalization
Normalization is a database design process in which complex database table is broken down into simple
separate tables. It makes data model more flexible and easier to maintain.
Database Normalization is a technique of organizing the data in the database. It is a systematic
approach of decomposing the tables to eliminate data redundancy and inconsistency. The data is
said to be redundant if there is duplicate or repeated data in the table.
Normalization divides the larger table into the smaller table and links them using relationship. It
increase clarity in organizing data in the database.
For example:
Below table shown is our database without normalized. Here in table we can see that for the large records
of this table, there would be multiple data row of same values especially in the country and city column.
So, we can normalize the table by splitting it into two tables where one table only stores the location area
of each person name and could be referenced by some unique id. Say Area code.
Types of Normalization
1NF (First Normal Form):
A table is said to be in first normal form if it has atomic values. There shouldn't be any repeating
groups of attribute in the table. First normal form sets the very basic rules for an organized
database.
o The data field should be a single (atomic) valued attribute/ columns.
o It eliminates duplicates rows and columns from the same table.
o It minimizes the data redundancy in the database table.
To remove partial dependency, a table can be divided and attributes creating partial
dependency are removed in some other tables.
Situation of Dependency:
Let’s take an example of table student with student_id, name, address and age as its columns.
Student_id Name Address age
Here student_id is the primary key which can identify each records uniquely and can be used to fetch
any row of data from this table.
Here we can get name, address and age of the student easily from their student_id. Which means each
column can be fetched using primary key. So, all needed is student_id and every other column depends
on it or can be fetched using it.
This is called dependency or functional dependency. And this kind of dependency must be in table to be
in second normal form.
Subject_id Subjectname
101 Math
102 Science
103 Nepali
Above we have two tables: student and subject for storing student’s and subject’s information. Now, let’s
make a table named Mark storing student’s mark in respective subjects with subject teacher.
In above table student_id is used to get student’s information where as subject_id is used to get subject
name. The combination of student_id and subject_id is the primary in above table. It is because if we
want to get mark of student with id 15 then we cannot get because we don’t know which subject. Here
we have to give sudent_id and subject_id to uniquely identify any row.
Is there a partial dependency in above table? Obviously, yes. In the given table Mark column name
teacher is only dependent on the subject, for math there is Bishnu for science Umesh and so on. But the
Website: www.bkbhusal.com.np 13 YouTube Channel: www.youtube.com/BkBhusalEduZone
Computer Science Reference Note for Grade-XII E-mail ID: bkbhusalinfo@gmail.com
primary key is the combination of student_id and subject_id, teacher’s name depend only on subject, i.e.
subject_id not on the student id.
This situation is known as partial dependency, where an attribute/ column in table depends on only a
part of primary key not on the whole key.
Mark:
Score_id Student_id Subject_id Marks
1 15 101 55
2 15 102 65
3 16 103 88
Summary:
For table to be in second normal form, it should be in first normal form.
Partial dependency exists, when non primary key attribute depends only on a part of
primary key instead of complete primary key.
Partial dependency can be removed by breaking a table and removing attributes causing
partial dependency.
In above table, student_id and subject_id are the primary key. The column exam_name depends on both
student_id and subject_id. But, the Full_marks depends on the Exam_name. The first term exam might
have 500 full mark but the second term may have 300 or others. Here exam_name is neither primary key
nor the part of primary key still, Full_mark depends on it. So, here full_mark which is non-primary key
attribute depends on another nonprimary key attribute known as Exam_name. This situation is known as
transitive dependency.
Score Table:
Score_Id Student_Id Subject_Id Marks Exam_Id
1 15 101 55 11
2 15 102 65 12
3 16 103 88 13
Exam Table:
Exam_ID Exam_Name Full_Marks
11 First Term 500
12 Second Term 300
Example of normalization:
Un-normalized Table:
Employee Id Name Address Vehicle
101 Ram Kathmandu Sales
102 Bikky Bhaktapur Marketing, Export
103 Anusha Lalitpur import
Here the non-primary key attribute salary dependent on the employee id only. Here Employee id and
department are the candidate key. This violates the rule that “no non primary attribute is dependent on
the part of primary key or on the subset of candidate key.”
Employee Id Department
101 Sales
102 Marketing
102 Export
103 import
Here, Employee Id is the primary key and all other are non-primary key attributes. The non- primary key
attribute HoD is dependent on non-primary key attribute Department. Here, transitive dependency
occurs. To remove it we can decompose table as:
Client 4
Disadvantages:
The size of centralized database is large which increases the response time of fetching data.
It is difficult to update the centralized database.
If sever gets damaged entire data will be lost.
Memory
Memory
Database
Location 1
Database
Communication
Channel Location 2
Database
Memory
Advantages:
The system can be expanded by including new computers and connecting them to the distributed
system.
Distributed database is more reliable than centralized database.
The performance and service are better.
Large numbers of users are supported.
One server failure will not affect the entire data set.
Disadvantages:
It is difficult to administrate and manage the database
It is expensive to set up.
This database has high risk of hacking and data theft.
Data dictionary:
A data dictionary is a file which contains meta-data that is data about data. It also called information
system catalogue. It keeps all the data information about the database system such as location, size of
the database, tables, records, fields, user information, recovery system, etc.
Data integrity:
Data integrity referees to the validity or consistency of data in database. It ensures that the data should
be accurate and consistent.
Mainly there are 3 types of data integrity constraints used in the database system. They are as:
1. Domain integrity constraints: it defines a set range of data values for given specific data field. And
also determines whether null values are allowed or not in the data field.
2. Entity integrity constraints: it specify that all rows in a table have a unique identifier, known as the
primary key value and it never be null i.e. blank.
3. Referential integrity constrains: it exists in a relationship between the two tables in a database. It
ensures that the relationship between the primary keys in the master table and foreign key in child
table are always maintained.
Data Security:
Data security is protection of data in database system against unauthorized access, modification, failure,
losses or destruction. The authorized access means only right people can get the right access to the
right data.
The SQL statement for creating, dropping, and altering database and table
XAMPP provides a GUI environment to perform any operations on the database. However, it also
provides an option to use SQL statements to perform any operations SQL statements are used in the
SQL menu in phpMyAdmin. The SQL statements used in XAMPP also work well with most of the
databases.
Creating a database:
Syntax: CREATE DATABASE databasename;
Example: CREATE DATABASE School;
Deleting column
Syntax:
ALTER TABLE table name
DROP COLUMN column_name;
Example: ALTER TABLE Students
DROP COLUMN Email
Modifying column (changing the data type of a column in a table)
Sytnax:
ALTER TABLE table name MODIFY COLUMN column_name datatype:
Example: ALTER TABLE Students
MODIFY COLUMN Class int
Deleting table
DROP TABLE table_name,
SQL statement to insert, select, update and delete data
Syntax Example: DROP TABLE Students:
Inserting data
Syntax
INSERT INTO table name (column1, column2 column3,...) Example: INSERT INTO Students (StudentID,
FName, LName, Address, Class)
VALUES (valuel, value2, value3.);
VALUES ('101', 'Ram', Sharma', Pokhara', 7);
Selecting data iselecting data from a database);
Syntax SELECT column1, FROM table name column2.
Example: SELECT * FROM Students; (This will select all the columns from the table Students] SELECT
FNAME. LNAME FROM Students: [This will select only the First Name and Last
Name from the table Students.]
Selecting data using conditions
Syntax SELECT column1, column2....
FROM table_name
WHERE condition;
Web References:
https://www.javatpoint.com
https://www.w3schools.com
https://www.tutorialspoint.com
https://www.google.com
https://www.wikipedia.org
Website: www.bkbhusal.com.np 20 YouTube Channel: www.youtube.com/BkBhusalEduZone