Database Management System Notes
(Libre office base)
A Database Management System is a software package with computer programs that controls the creation,
maintenance, and use of a database. It allows organizations to conveniently develop databases for various applications.
A database is an integrated collection of data records, files, and other objects. A DBMS allows different user application
programs to concurrently access the same database.
Well known DBMSs include Oracle, IBM DB2, Microsoft SQL Server, Microsoft Access, PostgreSQL, MySQL,
FoxPro, and SQLite.
A database model is basically used by the following users:
1. Developers: design and develop a database.
2. Administrators: keep track on database and check authorization to provide access to the users. (Admin) / DBA
3. End users: are the group of people who really use the database program. For example, in a school, teachers and
students are the end users as they use the database every day.
Data can be organized into two types:
1. Flat File: A flat file is a simple type of data storage format in which data is stored in a single table with a series
of rows and columns. It is used to store small amount of data. Example: MS Excel
2. Relational: A relational database uses multiple tables with defined relationships between them to store data. It
is used to store huge amount of data and can be accessed and queried using Structured Query Language (SQL).
Example: MS Access, MY SQL
Advantages of Database
1. Reduces Data Redundancy -In the event of requiring the same data field in several tables the data field
might get repeated in number of tables. This is called as data redundancy. This can be reduced by using
DBMS tools.
2. Reduces Data Inconsistency -By minimising data redundancy, chances of inconsistent data being stored is
reduced. For example, it should not happen that the name of the student is changed in one table and not in
another. Such inconsistency is reduced by using a DBMS.
3. Increases Data Integrity - databases provide mechanisms to enforce data integrity constraints, ensuring that
data is accurate, consistent, and reliable. This helps maintain the quality of data.
4. Sharing of Data -If the same data set is required for different applications then the database can be shared
with other applications. Hence using a database means making once and using it repeatedly for multiple
applications.
5. Data Security -Unauthorized access can be controlled by assigning passwords to the users. The data might
be translated in such a manner that unauthorized users are not able to read it. This is known as encryption.
Both these measures increase the security of the database.
6. Increases Accuracy – Since data redundancy and inconsistency can be minimised in a database, the data is
retrieved accurately from the database.
7. Backup & Recovery - Database recovery techniques are used in database management systems (DBMS) to
restore a database to a consistent state after a failure or error has occurred. The main goal of recovery techniques
is to ensure data integrity and consistency and prevent data loss.
Disadvantages of Database
1. Cost: Setting up and maintaining a database system can be expensive, including hardware, software licenses,
and personnel costs.
2. Complexity: Managing databases can be complex, and organizations may require skilled database
administrators to ensure optimal performance, security, and reliability.
3. Performance Overhead: Databases introduce a performance overhead due to the need to read and write data to
storage and perform complex queries. Poorly designed databases can suffer from slow performance.
4. Single Point of Failure: If not designed for redundancy, a centralized database can become a single point of
failure, risking data loss in case of hardware or software failures.
Page 1 of 10
5. Compatibility Issues: Different database management systems (DBMS) have variations in SQL syntax and
features, which can lead to compatibility issues when migrating or using different DBMS.
6. Security Concerns: While databases offer security features, they are still vulnerable to security breaches if not
configured and maintained properly.
7. Resource Consumption: Databases can consume a significant amount of system resources, including CPU,
memory, and disk space.
Data Models
A database can be designed in different ways depending on the data being stored. This structure of database
is known as data model that describes the manner in which data will be stored and retrieved.
A data model consists of components for describing the data, relationships among them and the constraints
that hold data. There are different data models such as hierarchical data model, network data model and
relational data model.
Hierarchical Data Model
In this model the data is organized into a tree like structure. The data is stored in the form of records. A record is a
collection of fields and its data values.All these records are linked to each other at various levels, thereby forming a
hierarchy. For example, in Fig. 8.1 the data of a company is stored using a hierarchical data model.
Network Data Model
In this model, multiple records are linked to same master file. It is also considered as an inverted tree where aster is
present in the bottom of the tree and the branches contain information linked to the master. In Fig. 8.2, the data of the
company is represented using the network data model.
Relational Data Model
This data model is based on the principle of setting relationships between two or more tables of the same database. It is
the most commonly used database model.
Page 2 of 10
DBMS (Relational Database Management System)
It is a type of database. It uses a structure that allows us to identify and access data in relation to another piece of data in
the database. Often, data in relational database is organized into tables. In a relational database each row is defined in
the table is a record with a unique ID called the key (PRIMARY KEY).
Relational Data Model Project Deadline This data model is based on the principle of setting relationships between two
or more tables of the same database. It is the most commonly used database model. Let us study about this model in
detail. The Relational Database Model was proposed in 1970 by E. F. Codd.
Key components of Database
• Table – A table is a collection of logically related records. It is organised as a set of columns, and
can have any number of rows. For example, the Employee table can have columns, namely name,
designation, department and have records or rows having data of 100 employees.
• Columns are referred as fields. A field describes a specific property of a record, that is why a field is also
known as an attribute.A field holds the data values of one type of data for several persons. For example, in the
Employee table the field “Emp Name” will hold the names of employees of an organisation.
• Rows are referred as records. A single record is also known as tuple.A record holds the data values of all the
fields for a single person or object in a table. For example, in the Employee table with the field names as Name,
Designation, Department, the data values of all the fields for an employee may be (‘Abhinav’, ‘Manager’,
‘Finance’) and this forms one record.
• A set of characters that represents a valid value is known as data or data value or data item.
Types of Keys in Database
1. Primary Key – A primary key or simply a key is a field that uniquely identifies a row in a table. The key
identifier can be the value of a single column or of multiple columns. The primary key is a unique identifier for
the table. The column or combinations of columns that form the primary key have unique values. At any time,
no two rows in the table can neither have same values for the primary key nor can data value for such field be
left blank. For example, in a student table, each student has a unique roll no., which forms the primary key.
Page 3 of 10
2. Composite Primary Key – Composite primary key is a key of two or more attributes that uniquely identifies
the row.If, in a table we use more than one fields to identify a record, it is known as a composite key. For
example, we may form a composite key consisting of fields roll no. and name.
3. Foreign Key – A foreign key is a field or a set of fields in a table that refers to the primary key of another
table.If a field or a combination of fields of one table can be used to uniquely identify records of another table,
then that particular field is known as the foreign key. This foreign key helps to build a relation between two
tables.
4. Alternate Key – An alternate key is a candidate key that is not chosen to be the primary key.Out of the
candidate keys, one or two are made as primary keys. The others are the alternate keys. Hence, if Roll Number
is made as the primary key, Admission Number is the Alternate key.
5. Candidate Key – A candidate key is a unique key that can be used as a primary key.All the field values that are
eligible to be the primary key are the candidate keys for that table. Such fields can neither be left blank nor can
have duplicate values. So in the table Student Marks, Enrollment Number and Roll Number both are candidate
keys.
Objects of an RDBMS
An object in a database is a structure or a feature that is used to store, represent or retrieve data. In fact a
database is a collection of these objects that work on multiple sets of data related to each other. Various
objects in a database are as discussed below:
•Table – As mentioned before, a table is the basic unit of any DBMS. The data is first stored in tablesin row and
column format. A column represents a field or an attribute while a row represents a record.
•Forms – A form is a feature of a database using which we can enter data in a table in an easy and user friendly manner.
A form consists of text boxes, labels, radio buttons, list boxes, check boxes etc. that give a user friendly interface for
entering data. The data entered through the forms is stored in tables.
•Queries – A query is used to retrieve the desired information from the database. In simple terms, it is a question asked
from the database. For example, if we want to view the names of only those students who have scored more than 50
marks, then we post a query. The data set matching the given criterion is retrieved from the table and displayed on the
screen.
•Reports – The output of a query may be displayed in the form of reports. The usual result of the query is in the form of
rows and columns. But if we want the report to be formal and in proper layout, then we can use the Reports feature of
RDBMS.
Data Types:
Datatypes are used to identify which type of data (value) we are going to store in the database.
Fields themselves can be of different types depending on the data they contain. Data types in base are broadly
classified into five categories listed below.
• Numeric Types • Alphanumeric Types • Binary Types • Date time • Other Variable types
Numeric Types: Numeric data types are used for describing numeric values for the field used in the table of a
database. Numeric data types in a database can be used for storing information such as mobile number, roll
number, door number, year of school admission, true or false statements, statistical values, etc.The different types
of numeric data types available are listed here.
Page 4 of 10
Alphanumeric Types:
Binary Types:
Binary data types are used for storing data in binary formats. Binary data types in a database can be using for
storing photos, music files, etc. In general, files of any format can be stored using the binary data type. The
different types of binary data types available are listed here.
DATE TIME:
Date time data types are used for describing date and time values for the field used in the table of a database. Date
time data types in a database can be used for storing information such as date of birth, date of admission, date of
product sale, etc.
The different types of date time data types available are listed here.
Page 5 of 10
Currency Data Type – The currency data type indicates the monetary values and can be stored using currencies of
various countries. For example $100, £ 500 or Rs. 25.50.
Boolean – In boolean data type there can be only two values- True or False. This also can be given in multiple
formats like Yes/No, True/False, On/Off.
Binary – The Binary data type used to store digitized images and sounds that comes as long string of zeros and
ones. It is possible to store photos of the products or employees, or sound snippets or voice messages in Base
database.
Field PropertiesTo change the field properties table structure in design view has to be changed. To set the field
properties, steps will be followed as: Select the table > Right click > Select the option Edit > the table Design View
window will open
In design view there are different properties of fields according to the data type set for each field.
The properties of numeric / character data type data is given below :
Like AutoValue (for Numeric)– if set to yes then field will get the auto numeric values.
Length (for Numeric & character both) – By default length of the field is 10 but the size of the field can be set to
maximum length.
Default Value (for Numeric & character both) – A default value can be set for a field if user don’t provide any
value while entering the values in the table.
Format example(for Numeric & character both) – This property helps to set the format of the data entered in
the field such as 91-222-333.
SQL (Structured Query Language)
SQL (Structured Query Language) is the language used in RDBMS for writing queries. Using SQL, a user can create
queries to fetch and manipulate the data of the database.
The SQL commands are of two types
1. Data Manipulation Language (DML)
2. Data Definition Language (DDL)
Data Manipulation Language (DML)
A DML (Data Manipulation Language) is a computer programming language used for adding (inserting), modifying
(updating) and data in database. The commands that fall under this category are listed as follows:
1. SELECT – It is used to retrieves or fetch the data from the table.
TO FETCH ENTIRE RECORD OF TABLE [* means ALL records]
Page 6 of 10
SYNTAX: SELECT * FROM <Table_Name>;
EXAMPLE: SELECT * FROM employee;
TO FETCH RECORD OF SELECTED FIELDS FROM TABLE
SYNTAX: SELECT <Field1, Field2,…> FROM <Table_Name>;
EXAMPLE: SELECT e_name, e_id FROM <Table_Name>;
SELECT Command Clauses
WHERE clause specifies a criteria about the rows to be retrieved.
ORDER BY clause specifies an order (ascending/descending) in which the rows (records) are to be retrieved.
To retrieve all records:
SELECT * FROM <Table_Name>;
To retrieved records from specific fields:
SELECT Field1, Field2,… FROM <Table_Name>;
By using WHERE clause:
SELECT * FROM <Table_Name> WHERE condition;
SELECT Field1, Field2,… FROM <Table_Name> WHERE condition;
By using ORDER BY clause:
By default Ascending order
SELECT * FROM <Table_Name> ORDER BY EName;
In descending order
SELECT * FROM <Table_Name> ORDER BY EName DESC;
2. INSERT – The insert command is used to add one or more records to a table. There are two methods to use the
INSERT command.
Method 1:
SYNTAX: INSERT INTO <Table_Name> (Field 1, Field 2,….) VALUES (Value 1, Value 2,….);
EXAMPLE: INSERT INTO employee (‘e_id’, ‘e_name’,) VALUES (1, “Mukesh”);
Method 2:
SYNTAX: INSERT INTO <Table_Name> VALUES (Value 1, Value 2,….);
EXAMPLE: INSERT INTO employee VALUES (1, “Mukesh”);
3. UPDATE – Sometimes, you need to modify the existing records in the table. The UPDATE command of the
SQL can be used for this purpose.
SYNTAX: UPDATE <Table_Name> SET Column1 = Value1, Column2 = Value2,…. WHERE condition;
EXAMPLE: UPDATE employee SET Last_Name=‘Sharma’ WHERE E_ID=101;
4. DELETE – It is used to remove the existing records from a table.
SYNTAX: DELETE FROM <Table_Name> WHERE condition;
EXAMPLE: DELETE FROM employee WHERE E_ID=101;
GROUP BY Statement
The GROUP BY statement groups rows that have the same values into summary rows, like “find the number of
customers in each country”.
The GROUP BY statement is often used with aggregate functions (COUNT, MAX, MIN, SUM, AVG) to group the
result-set by one or more columns.
GROUP BY Syntax:
SELECT FUNCTION(ColumnName) FROM table_name WHERE condition GROUP BY column_name;
Page 7 of 10
Example:
SELECT COUNT(CustomerID), country FROM customers GROUP BY country;
Example - Consider the following table and answer the given questions :
TABLE: Booking
Booking_No Pass_Name Boarding Destination Status
112455 AMIT DELHI JAIPUR BOOKED
123980 SNEHA BANGLORE DELHI CANCEL
234067 RAHUL DELHI MUMBAI BOOKED
289565 SHIVI JAIPUR AGRA CANCEL
i) Display Booking_No and Pass_Name whose Boarding is DELHI.
ii) View the data of passengers whose name starts from ‘S’.
iii) Insert an new record having values 289956, DEEPA, MUMBAI, DELHI, BOOKED
iv) Change the Boarding of AMIT from DELHI to CHENNAI.
v) Delete the records of passengers who have booked their tickets.
Answers -
i) Select Booking_No, Pass_Name from Booking
where Boarding = ‘DELHI’;
ii) Select * from Booking
Where Pass_Name Like ‘S%’;
iii) Insert INTO Booking
Values(289956,’ DEEPA’, ‘MUMBAI’,’DELHI’,’BOOKED’);
iv) Update Booking Set Boarding = ‘CHENNAI’ Where Pass_Name = ‘Amit’;
v) Delete from Booking where Status = ‘BOOKED’;
Data Definition Language (DDL):These commands are used to define and modify the structure
of a database. The commands that fall under this category are listed as follows:
1. CREATE – It is used to create a new database or table.
CREATE DATABASE
SYNTAX: CREATE DATABASE <DATABASE_NAME>;
EXAMPLE: CREATE DATABASE myschool_db;
example: Write a command and query to create the structure of a table named “student1”.
Roll_no Class Name Marks
Ans: CREATE TABLE Student1 (Roll_No INTEGER, Class VARCHAR(3), Name VARCHAR(30), Marks
INTEGER);
2. ALTER – It is used to modify the structure of an existing database or table.
TO ADD COLUMN (FIELD)
SYNTAX: ALTER TABLE <Table_Name> ADD COLUMN <Column_Name><Data_Type>;
Page 8 of 10
EXAMPLE: ALTER TABLE employee ADD COLUMN e_locvarchar(50);
TO REMOVE/DROP COLUMN (FIELD)
SYNTAX: ALTER TABLE <Table_Name> DROP COLUMN <Column_Name>;
EXAMPLE: ALTER TABLE employee DROP COLUMN e_loc;
3. DROP – Deletes an existing database or table.
TO DROP TABLE
SYNTAX: DROP TABLE <Table_Name>;
EXAMPLE: DROP TABLE employee;
Referential Integrity
Ans: Referential Integrity is implemented when the user wants to fetch data from two or more tables.
This is possible only if all the tables have at least one common field. Referential Integrity (RI)is a rule
in RDBMS. It states that a foreign key must have a matching primary key, i.e., all its references must be
valid and the users cannot accidentally delete or modify data.
Referential integrity helps to avoid:
• Adding records to a related table if there is no associated record available in the primary key table.
• Changing values in a primary if any dependent records are present in associated table(s).
• Deleting records from a primary key table if there are any matching related records available in
associated table(s)
Relationship -
Relationships between Tables While working with multiple tables, you need to check the redundancy and
inconsistency of data. The record for a particular entity should neither be repeated nor different data values should
appear for a single entity in the database. This is done by setting relationship between the tables of a database. The
most important prerequisite for setting a relationship is that there must be a common field(s) between the two
tables to create a relationship.
There are three types of relationship
One-to-One relationship - In this type of relationship, one specific record of a master table has one and only one
corresponding record in the transaction table. For example, the record for Admission_No in the master table
(Student_Detail) will have only one corresponding record of same value of Admission No in the transaction table
of Student_ Result. This is because no two students will be given same admission number. Similarly one person
can have only one ticket to get entry into a stadium to view the match. So relationship between Student and
Admission number and a person and his ticket number will be one-to-one relationship.
Page 9 of 10
One-to-Many relationship - This is one of the most common types of relationship between the tables in a
database. As the name says, in this type of relationship, one specific record of the master table has more than one
corresponding records in the related transaction table. For example, one teacher can teach multiple students or
multiple classes, or one person can sell multiple products. So we can say that there is a one to may relationship
between a teacher and class or teacher and student or seller and products
Many-to-Many relationship - In this type of relationship, there will be multiple records in the master table that
correspond to multiple records in the transaction table as well. Generally this type of relationship is set when
certain records have to be saved more than once in both the related tables. For example, a teacher in a school may
hold multiple responsibilities such as class teacher, an activity in charge or examination in-charge. For each
responsibility the teacher might be attached with multiple students. So this type of relationship will be many to
many relationship. Similarly a shopkeeper may sell multiple products to multiple customers. So many-to-many
relationship exists between a product and a customer.
Advantages of Relating Tables in a Database There are various advantages of relating tables in a database. Few of
them are as given below.
• A relationship can help prevent data redundancy.
• It helps prevent missing data by keeping deleted data from getting out of synch. This is called referential
integrity.
• Creating relationships between tables restricts the user from entering invalid data in the referenced fields.
• Any updation in the master table is automatically reflected in the transaction tables
Page 10 of 10