0% found this document useful (0 votes)
75 views

Database Management Systems Lecture Notes

The document discusses Database Management Systems (DBMS). It describes DBMS as application software that allows users to create, define, and manipulate database contents easily. The key components of a DBMS are outlined as the Data Definition Language (DDL) subsystem, Data Manipulation Language (DML) subsystem, database engine subsystem, application generation subsystem, data administration subsystem, and data dictionary. Examples are provided of how to use DDL commands like CREATE, DROP, and ALTER to define and manage database tables. DML commands like INSERT, SELECT, UPDATE, and DELETE are also explained for manipulating data. Practice exercises demonstrate how to implement DDL and DML commands in SQL.

Uploaded by

natembeatallia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

Database Management Systems Lecture Notes

The document discusses Database Management Systems (DBMS). It describes DBMS as application software that allows users to create, define, and manipulate database contents easily. The key components of a DBMS are outlined as the Data Definition Language (DDL) subsystem, Data Manipulation Language (DML) subsystem, database engine subsystem, application generation subsystem, data administration subsystem, and data dictionary. Examples are provided of how to use DDL commands like CREATE, DROP, and ALTER to define and manage database tables. DML commands like INSERT, SELECT, UPDATE, and DELETE are also explained for manipulating data. Practice exercises demonstrate how to implement DDL and DML commands in SQL.

Uploaded by

natembeatallia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Database Management Systems (DBMS) 2023

TOPIC: DATABASE MANAGEMENT SYSTEMS (DBMS)

Sub-topics

o Components / Elements of a DBMS


o Functions and services provided by a DBMS
o Features of DBMS
o Implementation of a Database system

A Database Management System (DBMS) is application software that allows creation, definition
and manipulation of database contents, allowing users to store, process and analyze data easily.
DBMS provides us with an interface or a tool, to perform various operations like creating
database, storing data in it, updating data, creating tables in the database etc.

The components of DBMS

A DBMS has several components, each performing very significant tasks in the database system
environment. Below is a list of components of a DBMS:-

1. Data Definition Language (DDL) Subsystem/ component


2. Data Manipulation Language (DML) Subsystem / component
3. Database Engine Subsystem
4. Application Generation Subsystem
5. Data Administration Subsystem
6. Data Dictionary

1) DDL (Data Definition Language): DDL is a language used by Database Management


systems (like Oracle, SQL, MYSQL etc.) that allows users to define the database
structure, specify the data types (attributes) and constraints on the data to be fed in the
database system.

©Juliet 2023 Page 1


Database Management Systems (DBMS) 2023

Note: Data type in programming languages refer to the format of data supported by a specific
language

SQL and MYSQL support the following data types:

Format of data Description Keyword used (keyword


refers to a reserved word that
has special meaning in a
language)
Characters Accept data in form of text text
Numbers Accepts data in form of Integer
numbers
Alphanumeric characters Accepts a combination of varchar
different data formats such as
characters, numbers, special
characters etc.
Date Accepts data in form of date date
format
Float Accepts whole numbers with float
decimal points

Double Accepts whole numbers with double


precision points

SQL and MYSQL support the following DDL commands:-

1. CREATE Command: - used to create a database, tables and views (virtual


database tables that fully depend on attributes of an existing permanent created
table).
2. DROP Command: Used to delete database objects i.e. deletes a database,
database tables or database views.
3. ALTER Command: used to amend database table attributes .i.e. used to:-

©Juliet 2023 Page 2


Database Management Systems (DBMS) 2023

(i) Add new attributes


(ii) Delete attributes
(iii) Changing data type

1. The CREATE DDL command: This command is used to create objects such as Tables,
Views and databases.

Command Syntax: CREATE object to be created object name;

Practice Exercises:

1. Creating databases using MYSQL/ SQL

1. Write MYSQL/ SQL command to create a database named KCAU

Command syntax: CREATE database databaseName;

Answer: CREATE database KCAU;

2. Creating databases tables using MYSQL/ SQL

Command syntax: CREATE table tableName (attribute names and data types);

Write MYSQL/ SQL command to create the table shown below:

Table Name: Students

Field Name Data type Size Constraint


StudentIDNumber integer Primary key
Firstname text
Surname text
EmailAddress Varchar 25 characters
Feebalance integer

©Juliet 2023 Page 3


Database Management Systems (DBMS) 2023

Answer:

Command syntax: CREATE table tableName (attribute names and data types);

CREATE table students (studentIDNumber integer, Firstname text, Surname text, emailaddress
varchar(17), Feebalance integer, primary key(studentIDNumber));

Creating database tables exercises

1. Write MYSQL/ SQL command to create the tables shown below:

Table Name: Courses

Field Name Data type Size Constraint


CourseCode integer Primary key
CourseName text
CourseDuration text
CourseDepartment text
CourseRequirements Varchar 25 characters

2. Table Name: Lecturers

Field Name Data type Size Constraint


LectureIDNumber integer Primary key
Surname text
Firstname text
Gender text
Qualifications Varchar 30 characters

©Juliet 2023 Page 4


Database Management Systems (DBMS) 2023

2. The DROP DDL Command: used to delete database objects.


3. The ALTER DDL Command: DDL command used to add, delete or modify columns in
an existing database table.

(a) Adding a new column to database table

Command syntax: alter table tablename ADD COLUMN columnName


datatype;

Example: alter table students add column PhoneNumber integer; varchar(15)

(b) Deleting a column from a database table:

Command syntax: alter table tableName DROP column columnName;

Example: alter table students drop column PhoneNumber;

(c) Changing data type (modifying the existing column):

Command syntax: alter table tableName MODIFY COLUMN columnName


Newdatatype;

Example: alter table students MODIFY column PhoneNumber varchar(15);

Creating Views/ Virtual Tables

In SQL, a view is a virtual table based on the result set of an SQL statement. A view
contains rows and columns just like a real table. The fields in a view are fields from a real
table in the database.

In SQL views are created using the command syntax shown below:

©Juliet 2023 Page 5


Database Management Systems (DBMS) 2023

CREATE VIEW View_name AS SELECT Column_name(s) FROM table_name


WHERE condition;

Exercise 1:

Using the course relation, create a view named DITCourses to extract CourseCode ,
CourseName andCourseDepartment for all courses offered by IT department

Answer: Create view DITCourses as select CourseCode , CourseName


,CourseDepartment from courses where CourseDepartment=”IT”;

Exercise 2:

Using the student relation, create a view named studentFeeBalance to extract


StudentIDNumber and surname for all the students with a feeBalance of 10,000 and
above

Answer: Create view studentFeeBalance as select StudentIDNumber, Surname from


students where Feebalance>=10,000;

2) Data Manipulation Language (DML): DML component allows users to issue


commands permitting them to manipulate data in a database. This manipulation involves
inserting data into database tables, retrieving existing data, deleting data from existing
tables and modifying existing data. DML is mostly incorporated in SQL databases.

Data Manipulation Commands supported by MYSQL/ SQL

SQL / MSQL support the following manipulation commands:

©Juliet 2023 Page 6


Database Management Systems (DBMS) 2023

1. INSERT Command
2. SELECT Command
3. UPDATE Command
4. DELETE Command

1) INSERT: This command adds one or more records to a database table. The insert
command syntax is

INSERT INTO tableName VALUES [value(s)];

Example: Insert into students values(100,”Jane”,”Kamau”,”12/06/1998”);

Exercise:

Insert the following records into your created student table:-

StudentIDNumber Firstname Surname EmailAddress FeeBalance


100 Janet Njoroge [email protected] 1000
200 James Otieno [email protected] 50
300 Janet Komu [email protected] 30000
400 Caroline Kamau [email protected] 26000
500 Dennis Njoroge [email protected] 300

2) SELECT: used to retrieve data inform of records (rows) from a database table.

The select command syntax is: SELECT [column name(s)] from [table name] where
[conditions]; Select is the most widely used DML command in SQL.

Example: SELECT StudentIDNumber, surname FROM students where


feebaance>30,00;

Exercise: - Write SQL command to extract all the student records from the student
relation

©Juliet 2023 Page 7


Database Management Systems (DBMS) 2023

3) UPDATE: used to modify data of one or more records. The update command syntax is:
UPDATE table_name SET column_name = new value where [condition];

An update command Example: UPDATE student SET marital_status=”married”


WHERE studentIDNumber=100;

Exercise: using the student relation, update the first record surname from kamau to
Otieno

4) DELETE: This command removes one or more records from a table according to
specified conditions.

Delete command syntax is: DELETE FROM table name where [condition];

Example: DELETE FROM students WHERE surname=”kamau”;

3) Application Generation Subsystem: - the part of the system that contains all the
facilities that could be used to help the user develop transaction intensive applications.
This procedure will usually require the user to perform complex and detailed tasks to
complete the transaction. This is where the Application Generation Subsystem comes in
useful as it provides easy to use screens where you enter the data, programming
languages and interfaces.
4) DBMS engine:-A DBMS engine is the part of the system that accepts and deals with
logical requests that are received from a variety of other DBMS subsystems. It then
works to convert them into physical equivalents and will then gain access to the database
along with its data dictionary as they are on a storage device.
5) Data administration subsystem: - helps users with managing the overall database
environment. It does this by providing facilities that give the user options for backup and
recovery of lost data, managing the system's security, query optimization, concurrency
control and change management.
6) Data Dictionary/ System Catalog Management/ Metadata repository: a data
dictionary is a collection of descriptions of the data objects or items in a database (data

©Juliet 2023 Page 8


Database Management Systems (DBMS) 2023

about data). The DBMS provides a data dictionary function in which descriptions of data
items are stored and which is accessible to users.

Characteristics of Database Management Systems

1. Data is stored in form of Tables/ Relations/ files: Data is never directly stored into the
database i.e. Data is stored into tables, created inside the database. DBMS also allows
having relationships between tables which makes the data more meaningful and
connected. You can easily understand what type of data is stored by looking at all the
tables created in a database.
2. Reduced Redundancy: DBMS follows Normalization which divides the data in such a
way that repetition is minimized.
3. Data Consistency: On Live data, i.e. data that is being continuously updated and added,
maintaining the consistency of data can become a challenge. But DBMS handles it all by
itself.
4. Support multiple user and Concurrent Access: DBMS allows multiple users to work
on the database data by updating, inserting or deleting data at the same time and still
manages to maintain the data consistency.
5. Query Language: DBMS provides users with a simple Query language which supports
query statements which can allow the database user to easily fetch data, insert, delete and
updated in the database contents.
6. Data Integrity: - The DBMS can ensure that no more than one user can update the same
record at the same time. It can keep duplicate records out of the database; for example, no
two customers with the same customer number can be entered.
7. Security: The DBMS also takes care of the security of data, protecting the data from un-
authorized access. A DBMS can be used to create user accounts with different access
permissions that can be used to restrict non-authorized user from accessing the database.

©Juliet 2023 Page 9


Database Management Systems (DBMS) 2023

8. Data Independence:-When a DBMS is used, the details of the data structure are not
stated in each application program. The program asks the DBMS for data by field name;
for example, a coded equivalent of "give me customer name and balance due" would be
sent to the DBMS. Without a DBMS, the programmer must reserve space for the full
structure of the record in the program. Any change in data structure requires changing all
application programs.
9. DBMS supports transactions, which allows us to better handle and manage data
integrity which is a core requirement of a database system.

Functions and Services provided by a DBMS

1) Data Storage Management: -DBMS provides a mechanism for management of


permanent storage of data in a database.
2) Data Manipulation Management: A DBMS allows users to retrieve, update and delete
existing data in the database.
3) Data Definition Services: The DBMS allows the user to define the database structure.
4) Data Dictionary/System Catalog Management/ metadata repository: a data
dictionary is a collection of descriptions of the data objects or items in a database. The
DBMS provides a data dictionary function in which descriptions of data items are stored
and which is accessible to users.
5) Database Communication Interfaces: The end-user's requests for database access are
transmitted to DBMS in the form of communication messages.
6) Authorization / Security Management: The DBMS protects the database against
unauthorized access, either international or accidental. It furnishes mechanism to ensure
that only authorized users can access the database.
7) Backup and Recovery Management: The DBMS provides mechanisms for backing up
data periodically and recovering from different types of failures. This prevents the loss of
data
8) Concurrency Control Service: Since DBMSs support sharing of data among multiple
users, a DBMS must provide a mechanism for managing concurrent access to the

©Juliet 2023 Page 10


Database Management Systems (DBMS) 2023

database. DBMSs ensure that the database is kept in consistent state and that integrity of
the data is preserved.
9) Transaction Management: A transaction is a set of database operations, carried out by a
single user or application program, which accesses or changes the contents of the
database. Therefore, a DBMS must provide a mechanism to ensure either that all the
updates corresponding to a given transaction is made or that none of them is made.
10) Database Access and Application Programming Interfaces: All DBMS provide
interface to enable applications to use DBMS services. They provide data access via
Structured Query Language (SQL). The DBMS query language contains two
components: (a) a Data Definition Language (DDL) and (b) a Data Manipulation
Language (DML).

©Juliet 2023 Page 11

You might also like