You are on page 1of 15

DBMS – Database Management System

Database:-
A base where we can store data?
Database is an Organized Collection of Related Data stored in Compact
Manner for Efficient Retrieval.
1. Organized Collection (Arranged & Adjusted Data)
2. Related Data (Of a specific Organization/Field Specific)
3. Compact Manner (Lesser Storage Space)
4. Efficient Access/Retrieval (Quick & Fast Access)

Database Management System:-


Database Management System is a software System that is used
to manage Database. In this software you can Create, Update, View and
Delete your Database and its data.

List of Various Database Management Systems:-


1/2*. Oracle (Oracle Company – Database Expertise)
1/2*. Microsoft SQL Server 2018 (No. 1 IT Company) => MS OFFICE
Above 2 database Management software are considered to
be the most efficient, effective database environment with extreme
sophisticated security techniques and they are in serious competition in
with each other... other DB management systems are
3. My SQL (Open Source) 4. Solar wind Database
5. DB 2 (from IBM – 3rd No – International Business Machine)
6. Alti Base (???)
7. Sy Base (SAP – System/Software Application & Product)
8. Informix (???) 9. Couch DB (?????)
10. Microsoft Access (Microsoft) 11. Teradata (????)
12. AdaBase (???) 13. Maria DB (???) 14. Mongo DB (????)

Your Database vs. Your Software? Which one is more


important in term of worth? Why?
Undoubtedly, both database and software are important as they
work together with each other. The relationship between database and
software is of body and soul. So, body is nothing without soul however
soul has its own existence and value. If only a software is hacked
without its database then nothing is lost but if software is hacked with
database then there is big problem.

Database Approaches:-
1. File Based Approach (Excel File?)
Each department of the organization has its own data
file separate from other department e.g. IT, Business,
Exam, Account, and Library. (Classic Approach)
2. Centralized Database Approach
Data is stored at a central place and accessible for all
department.
Which one is better approach?
Benefit of Centralized vs. Problem of File Based
Easy to Share & Use data Difficult to Share & Use data
Time Saving Time Wastage
Cost Effective More Costly
No Duplication More Redundant
Easy to Maintain Data Data Maintenance Problem
Data Accuracy Chances of Inaccurate Data
Data Security Insecure Data
Data/Result Consistency Data/Result Inconsistency
Fast Access Slower access to data

Problems of Centralize Database System


1. High Network Traffic (More load on central system)
2. Risk of Data Loss due to database failure (Single Storage)
3. Requires Expert (Database Administrator)
4. Costly Hardware (Database Server), Software (DBMS) and
Network (Sharing)

Installation of DATABASE MANAGEMENT SYSTEM (SQL SERVER 2017)


PRACTICAL WORK: Creation of Database, Tables and Relationships with
primary and foreign keys
Components of Database System
Table (File, Relation, Entity - as it has attribute)
Rows (Record, Tuple, Entity Instance)
 Each student in Student Entity is Entity Instance.
Column (Attribute, Property, Field)
Data Type of Columns (Int, String, Date, Numeric)
Primary Key:
A primary key is a column in table that uniquely identify each row
of the table…. 3 Ali could be in database student’s table with same
gender, age, department and area… Roll#, CODE can help us to
uniquely identify each Ali from those 3 Ali. Similarly as per our youtube
video, DeptID (PK) of Department Table is foreign key (FK) in student
table coz it is for establishing relationship of students with its
department.
 A table must have a primary key and maximum only one PK.
 Primary Key can never contains duplicates Values (only Unique Values)
 Primary key cannot allow Null (Absent) Value (should have some value)
Foreign Key:
For establishing relationship between two tables… When primary
key of 1st table is linked and put in second table for establishing
relationship then this Primary key (Column) in 2nd table is known as
Foreign Key.
 A table can have more than 1 Foreign Key.
 A foreign key can contain Null (Absent) Value.
 A foreign key can contain duplicate Value.
 A foreign key can however only contains those value that are
present in its Primary Key…
Types of Relationship between Tables:
1-1: (NO Rule, PK of any one table can be set as FK in other table)
Citizen Table (1) vs. NADRA Table (1)
Country Table (1) vs. Presidents Table (1)
University Table (1) vs. Directors Table (1)
(If two tables are in one to one relationship then why not
they are in single table or we can say that we can merge the
2nd table with first by making it an attribute of 1st table)

1-M: (Rule: PK of One table should become FK of Many Table, Not Vice versa
otherwise data duplication problem will rise)

Department Table (1) vs. Student Table (M)*


Country Table (1) vs. City Table (M)
Customer Table (1) vs. Order Table (M)
M-M: (Rule, We will have to pick the Primary Key of Both tables and
then to put them as foreign key in a third table otherwise we will data
duplication problem)
 Student Table (M) vs. Subject Table (M) *
 Teacher Table (M) vs. Subject Table (M)
 Books Table (M) vs. Authors Table (M)
 Customer Table (M) vs. Product Table (M)
 Student Table (M) vs. Assignment Table (M)
 Student Table (M) vs. Teacher Table (M)
 Product Table (M) vs. Customer Table (M)
 Employee Table (M) vs. Duty Table (M)
 Authors Table (M) vs. Books Table (M)
Types of Database Backup
Full Database Backup vs. Incremental Database Backup
(Backup of recent Changes or changes in database since last backup)
Online Database Backup (Active) vs. Offline Database Backup (Disconnect)
(When database is in access for users or stopped from users)
 Full database backup is normally taken when database is offline (not in
access of users)
 Incremental database backup can be taken while database is online
(available for users to work with)
Types of Database Backup
Backup is used to protect database from media failures or other errors. One or more of
database files may be physically damaged and get unusable after media failure. The most recent backup
can be used to replace the damaged files and reconstruct the data of your database.

There are two main types of database backups:

1. Full backup
2. Incremental backup

In addition database may be in two different states while performing a backup:

1. Online
2. Offline

Full backup

A full database backup is used to create a copy of all data of entire database. It requires a large
amount of storage space. However, a database can restore relatively quickly using a full back up as it
requires to simply copying the backup files.

Incremental backup

An incremental backup creates a copy of only the data that have changed since the last backup.
Since an incremental backup only contains changes made to the database, the user must perform a full
back up before the incremental database to restore the database at a later time. Incremental backup
requires small amount of storage space. However, it may take more time to restore a database.

Offline backup

An offline backup is a backup that is performed after a database has been shut down. The
database administrator must schedule a time to shut down the database and notify all users so they can
disconnect for the database.
Offline backup can be inconvenient for users as they must remember to complete all active
transactions and disconnect from the database before shutting down. Offline backup is performed by
using the commands of operating system. DBMS does not provide this facility as offline back is
performed when DBMS has been shut down.

Online backup

An online backup is a backup that can be performed while the database is running. The database
administrator does not have to shut down the database. The users do not need to disconnect. Online
backup are more convenient foe users as they perform no action.

Online backup is performed by using the commands of DBMS. DBMS should provide the facility
for online backup as DBMS is running when online backup is performed.

Database Constraints (Data Integrity Constraints (checks))


Integrity is (Consistency, Accuracy, Trust-ability)

1. Entity Integrity (Primary Key)


a. Records in each entity (table) must be unique or different from each
other.
2. Referential Integrity (Foreign Key)
a. Foreign key (Reference Key) must be derived from Primary Key we
can only have those value in a Foreign key that exist in its primary
key. However unlike primary key we can have duplicate or null values
in a foreign key.
3. Domain Integrity (Column data type (defined values/limits))
a. Values in each column should be in a specific domain for example
age column should allow date only, Quantity should allow integer
values only, CGPA 3.42 column can only contains Numeric(1,2)),
Email column should allow maximum 20 chars (AlphaNumberic) by
nVarChar(20)

Database Environment Types


Centralized Database Environment
a) Data of different department of an organization (e.g. PU
Jhelum, Lahore, and Gujranwala) will be maintained at single
central location.
b) All departments (let say 3 campuses) can access to that
centralize database with the help of some network (internet)
c) But what will happen if the internet of any one location is
down for hours? That department will not be able to access
any data of any other department even the data of its own
department.

Distributed Database Environment


a) Data of different department of an organization (e.g. PU
Jhelum, Lahore, and Gujranwala) will be maintained at each
department.
b) However all departments (let say 3 campuses) can access to
the distributed database with the help of some network
(internet)
c) If internet is available you can access the database of all
campuses at a single location otherwise if network is down
you can still have an access to your own local departmental
(campus) data.

Decentralized Database Environment


d) Data of different department of an organization (e.g. PU
Jhelum, Lahore, and Gujranwala) will be maintained at
department.
e) There is no network between campuses to access the
decentralize data.
f) What will happen if VC wants to see fee status of whole PU
(students of all 3 Campuses)?

Online QUIZ # 1 => 12:30 pm – 12:50 pm (20 MCQs)

Designing the Database


1. Library (Book Issuance) Management System
Entities /Tables:-
1. Book Table (BookID, ISBN#, Title, Author, Edition, Quantity, Subject, Type/Category)
2. Staff Table (StaffID, Name, Phone, Email, Designation, Address, …….)
3. Student Table (StudentID, Name, Phone, Email, Session, Section, Deptt, Address, ….)
4. Issuance Table
(IssuanceNo, BookFID, StaffFID, StudentFID, Issuance Date, Due Date, Return Date, Fine)

Relationship:-
1. Book Table vs. Staff Table (M - M => Issue)
2. Staff Table vs. Student Table (M – M => Issue)
3. Book Table vs. Student Table (M – M => Issue)
Practical Task: (Use Video 2 for Assistance)
You have to create a database with a name of dbLibrary in SQL
Server. Database will contain 4 tables having 4 Primary Keys
(one in each). Issuance table apart from its PK will also have 3
foreign keys as well.
You also need to add 3 student’s records, 3 book records, 3
staff members’ records and 5 issuance record in their
respective table.

2. Attendance (Student) Management System


Table/Entity:
1. Student Table (Roll#, Name, Deptt, Age, Section, Session )
2. Teacher Table (Teacher_ID, Name, Age, Designation, Deptt)
3. Subject Table (Subject_CODE, Subject_Name, CreditHour)
4. Attendance Table *
(Attendance_ID, Roll#_FID, Teacher_FID, Subject_Fcode, Date,
Time, Attendance_Status*)
Relationship
Student - Teacher (Attendance M – M )
Subject - Teacher (Attendance M–M)
Subject - Student (Attendance M–M)

3. University (Classes) Time Table Management System


Table:-
1. Class Table (ClassID, Name, Deptt, Section, Shift, Session, ROOM#)
2. Teacher Table (Teacher_ID, Name, Age, Designation, Deptt)
3. Subject Table (Subject_CODE, Subject_Name, CreditHour)
4. TimeTable* (TT_ID, Class_FID, Subject_FCODE, TEACHER_FID, DAY,
FromTime, ToTime)
Relationship:-
CLASS vs Teacher ( M - M )
Subject vs Teacher ( M - M )
Subject vs Class ( M – M )
4. Creation of Database of J. (ONLINE Shopping SYSTEM)
Table/Entity:-
1. Customer (CustomerID, Name, Age, Gender, City, Phone, Email, Address)
2. Product (ProductID, Code, Picture, Price, Description, Category)
3. Outlet (OutLetID, Name, Address, City)
4. Staff (StaffID, Name, Designation, Gender, Email, Phone, Address, Outlet_FID)
5. ORDER* (Order#, PRODUCT_FID, OutLet_FID, Customer_FID, STAFF_FID,
PaymentMethod, QUANTITY, Date, TIME, DISCOUNT, ORDER_STATUS)

DRAW ER-Diagram of Above 5 Tables & Whatsapp at 0332-8159859

Practice 1:- Draw database of Student Attendance and their


Class Time Table with ER-Diagram……
Practice 2:- Draw database of Student Result Management
System and their Class Time Table with ER-Diagram……
Practice 3:- Quiz # 2 (Create Database of Voting with ER-
Diagram)

ER – Diagram
(Entity (tables) Relationship Diagram)
Subject (M) (1-M)Assign Subject (1-M) Teacher (M)

QUIZ # 2 (Class Activity)


Draw database of Voting System along with ER-Diagram.
1. Make required Tables with relationships
a. Party: (PartyID, Name, Logo, Chairman, Members)
b. Candidate: (CandidateID, Name, City, CNIC, DOB, Gender, Address,
PartyFID)
c. Seat#: …………………………………………………………
d. Voter: (VoterID, Name, City, ThumbImpression, CNIC, DOB, Gender,
Address, Status, PollingStationFID)
e. Polling Station (PollingStationID, Name, Address, NoOfStaff,)
f. Polling Staff (StaffID, Name, Age, Address, Designation,PollingStationFID)
g. Vote (VoteID, VoterFID, CandidateFID, , Date, Time)
2. Draw an ER-Diagram for above tables
Paper Pattern / Course (75 Marks)
25 Marks – Database Concepts => Short Question (5*5)
15 Marks – Create a Database
15 Marks – Create ER Diagram for above Database
20 Marks – SQL Statements (10*2)
15 Marks – Normalization?

SQL – Structured Query Language


SQL is a Language which is use to ask different type of
questions (Commands) from the Structure or Data of
Database. Question to delete, insert, update or view
information from database.
If student table contains 5000 students and I want to delete student
that are from Sialkot? Solution is SQL Command
If student table contains 5000 students and I want to update student
that are from 6th Semester to 7th Semester? Solution is SQL Command

SQL (Structured Query Language)


SQL is a language used to ask different type of Query (Questions) from
the structure of database. Questions of fetching information such as
about Short Attendance Students, Total Books Issued this month,
Total Sale at the end of day etc. we may ask questions to edit, insert
or even delete data from the structure of database with the help of
SQL. SQL is not a programming language it is used by programmers in
software to insert, delete and fetch data and information from the
database. SQL is not Case Sensitive. e.g. Facebook is a software build
by using Php programming language, database and data of Facebook
is in My SQL. Php programmer use SQL Statements to fetch detail
from My SQL.
Type of SQL Commands:-
1. Data Definition Language (DDL)
Deals with database design and structure. We normally not use
these kind of command as most of DBMS now provide a very user
friendly environment (GUI) for such activities.
 Create Database, Create Table
 Drop Table, Drop Database
 Alter Column, Alter Data type etc.
2. Data Manipulation Language (DML):
Deals with the data of database. Still in use as data is huge in
volume how we can fetch student from 5000 students who has
not yet paid their fee.
 Select Queries / Commands (to fetch information)
 Delete Queries / Commands (to Delete data)
 Update Queries / Commands (to update data)
 Insert Queries / Commands (to Send/Save / Insert data in
database)
 Select Statement
Use of Select Clause for single, multiple or all columns from single table.
a. Use of Where Clause:
b. (Logical Operator {AND, OR, NOT})
c. (Comparison Operators {= != > < >= <= })
d. (Arithmetic Operators {+ - / * %})
e. Use of TOP N, Like, Between And, IN, IS etc.
f. Use of Order By Clause (ASC, DESC)
g. Use of Group By Clause
h. Group Functions, Date Functions

You might also like