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

Database

This document discusses database management systems (DBMS) and provides information about different types of databases, database environments, and database concepts. It defines a database as an organized collection of related data stored compactly for efficient retrieval. It also lists several popular DBMS like Oracle, Microsoft SQL Server, MySQL, and describes their main functions of creating, updating, viewing and deleting databases. The document compares centralized vs file-based database approaches and discusses database concepts such as primary keys, foreign keys, relationships between tables, and different types of database backups.

Uploaded by

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

Database

This document discusses database management systems (DBMS) and provides information about different types of databases, database environments, and database concepts. It defines a database as an organized collection of related data stored compactly for efficient retrieval. It also lists several popular DBMS like Oracle, Microsoft SQL Server, MySQL, and describes their main functions of creating, updating, viewing and deleting databases. The document compares centralized vs file-based database approaches and discusses database concepts such as primary keys, foreign keys, relationships between tables, and different types of database backups.

Uploaded by

Ruhma Zainab
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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.

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...
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 deptt has its own data file separate from other
departments. (Classic Approach)
2. Centralized Database Approach
Data is stored at a central place and accessible for all
department.
Which one is a better approach?
Benefit of Centralized vs. Problem of File Based
No Data Duplication Data Duplication
Easy to Maintain Data Data maintenance is difficult
Time & Cost Saving Time wastage & Costly
Lesser Storage Space Required More Storage Required
Data Consistency Inconsistency of Data
Easy to Share Problem in data sharing
Data Security More chances of data leakage
Easy Data Backup & Recovery Data Backup & Recovery Problem

Risks / Issue of Centralized Database Approach


1. High Risk of data loss due of data centralization.
2. Experts required in case of Centralized Database Management
3. Requires Better Hardware (Database Server), Software (DBMS) &
Network (internet) for data sharing across departments

Installation of DATABASE MANAGEMENT SYSTEM (SQL SERVER 2017)


PRACTICAL WORK: Creation of Database, Tables and
Relationships with primary and foreign keys
Components of a Database System
Tables (File, Relation, Entity (that has some attribute)) - Combination of Rows &
Column (Attribute, Data Field, Property)
Rows (Tuple, record, Entity Instance)
Primary Key:
Primary key is a column that identify a record. (Primary key is a column that
help you to uniquely identify (similar) records)
Primary key cannot contain duplicate values (Must be Unique)
Primary key can never contain a Null (Absent of) Value.
A table can only has one Primary key and should have one.

Foreign Key:
If a primary key of one table is linked in 2nd table for the purpose of
establishing relationship between two tables then primary key of first table in 2 nd
table is known as Foreign Key…. e.g. DeptID (PK) of Department Table is foreign
key (FK) in student table coz it is for establishing relationship of students with its
department.
Foreign key unlike Primary key can contain a NULL Value…
Foreign key unlike primary key can contain duplicate values…
But foreign can only contains values that are present in its primary key…

Data Type
Set of allowed values that can be entered/Put in a column
(Allowed value set) e.g. Data of birth column can only take date type of
data and Price or Quantity column can only take integer values.
Types of Relationship between Tables
1. ONE to ONE (NO RULE)
 Department Table vs. HODs Table
 Employee Table vs. Salary Detail Table
 Teams Table vs. Captain’s Table
(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)

2. ONE to MANY (Rule:- Primary Key of 1st (ONE) table is adjusted as


Foreign Key in 2nd (Many) Table but Primary Key of 2 nd (Many)
table cannot be adjusted as Foreign Key in 1 st (One) table)
Problem?
 Department Table (1) vs. Student Table (M)
 Company Table (1) vs. Employee Table (M)
 University Table (1) vs. Department Table (M)
 Scholarship Table (1) vs. Student Table (M)

3. Many to Many (RULE:- Primary Key of 1st or 2nd Table cannot be


set as Foreign Key of 2nd or 1st Table, respectively. How we can
create relationship then? By Creating a new Table)
 Student Table (M) vs. Subject 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)
Database Constraints for Data Integrity (Accuracy)
1. Entity Integrity (Each record in an Entity must be different from
other, with the help of Primary Key)
2. Referential Integrity (Reference Key/Foreign Key)
3. Domain Integrity (with the help of Data Types of Column)

Database Backup Types


Full Database Backup vs. Incremental Database Backup
Online Database Backup vs. Offline Database Backup
 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 (Detail…)


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.
Types of Database Environment
Centralized Database Environment
1. Database is maintained at a single central location for all
campuses/departments.
2. All Campuses/departments are connected to that centralized
database with the help of internet (some network).
3. Good to have… but what will happen if network is down? We will
not be able to access data of any campus/department or even our
own campus. e.g. Database of HBL stored at HBL Head Office
Karachi whereas is available for all branches.
Distributed Database Environment *
1. Database is maintained at different location for each
departments.
2. All departments are connected to distributed database of each
department with the help of internet (some network)
3. We will always have full access to our database even when
network is down for hours and we will also have access to
database of other departments or campuses as well (if network is
up).
e.g. Database of various outlets of J., each outlet maintains his
own data and is accessible for other lets and for main head as
well.
Decentralized Database Environment
1. Database is maintained at different location for each
departments. In a decentralized database, the computers are not interconnected via a
network.
2. Each departments is connected to its database only. A
departments cannot access the data of other department. As data
is not available to access via any network.
3. We will always have full access to our database even when
network is down for hours but we will have to make a lot of effort
each time when we need some data from other departments or
campuses as well. e.g. various campuses of PU i.e. Lahore,
Gujranwala, Ayubia, Jhelum.

Online QUIZ # 1 => Monday 12:30 pm – 12:50 pm


Creating the Databases!
Database of Library (Book Issuance) Management System?
Find Entities / Tables:-
1. Book (Book_ID, ISBN#, Title, Authors, Language, Edition, Fine/Day, Genra(Category))
2. Student (Student_ID, Name, Department, Session, Section, Age, Gender, Email, Phone,...)
3. Teacher (Teacher_ID, Name, Department, Age, Gender, Email, Phone, Designation, ...)
4. Employee (Emp_ID, Name, Department, Age, Gender, Email, Designation, etc……..)
5. Issuance Table
(IssuanceID, Teacher_FID, Student_FID, Book_FID, Emp_ID, Issue Date, Due Date, Return Date,
Fine)
( 1, 2, Null, 3, 21/12/2020, 25/12/2020, 28/12/2020, 300)
( 2, NULL, 1, 2, 23/12/2020, 28/12/2020, 29/12/2020, 100)
Find Relationships:-
1. Student Table vs. Book Table (M – M => Issuance)
2. Teacher Table vs. Book Table (M – M => Issuance)
Practical Task: (use Video 2)
Make a database in SQL Server Management studio with the name of
“dbLibrary” having 4 tables each with a Primary Key and along with
three foreign key in Issuance Table. You will have to add at least 3
student records, 3 teacher records, 3 book records and with at least 5
records of book issuance.

Database of Attendance (Student) Management System


Table:-
1. Student Table (RollNo, Name, Age, Deptt, Gender, Email, Class_FID …)
2. Class Table (Class_ID, Class_Name(Degree), Section, Session, Shift, Room#, #ofStudents)
3. Teacher Table (Teacher_ID, Name, Deptt, Designation ……)
4. Subject Table (Subject_ID, Code, Credit Hours)
5. Attendance Table*
(Attendance_ID, SUBJECT_FID, STUDENT_FID, TEACHER_FID, DATE,
DAY, TIME, Attendance Status*)
Relationship
Student vs. Class (1 - M)
Student vs. Teacher (M – M => Attendance)
Student vs. Subject (M – M => Attendance)
Teacher vs. Subject (M – M => Attendance)
Create a Database (to store data) of Time Table (Classes)
Table/Entity:
1. Class Table (Class_ID, Class_Name(Degree), Section, Session, Shift, Room#,
#ofStudents)
2. Teacher Table (Teacher_ID, Name, Deptt, Designation, ……)
3. Subject Table (Subject_ID, Code, Credit Hours)
4. TimeTable *
(TimeTable_ID, Teacher_FID, CLASS_FID, SUBJECT_FID, Time, Days)

Relationship:
Class vs. Teacher (M – M => Timetable)
Class vs. Subject (M – M => Timetable)
Teacher vs. Subject (M – M => Timetable)

Create a Database to Store Classes Time Table


& Student Attendance
Create a Database of Time Table + Attendance
Table/Entity:
1. Teacher Table (Teacher_ID, Name, Deptt, Designation,)
2. Subject Table (Subject_ID, Code, Credit Hours)
3. Student Table (RollNo, Name, Age, Deptt, Gender, Email, Class_FID …)
4. Class Table (Class_ID, Class_Name(Degree), Section, Session, Shift, Room#, #ofStudents)
5. TimeTable *
(TimeTable_ID, Teacher_FID, CLASS_FID, SUBJECT_FID, Time, Days)
6. Attendance Table*
(Attendance_ID, SUBJECT_FID, STUDENT_FID, TEACHER_FID, DATE,
DAY, TIME, Attendance Status*)

Creating Database of Shopping (J.) Store


Table/Entity:
1: Customer (CustomerID, Name, Contact, Email, Address, City)
2: Product (ProductID, Name, Desc, Price, Color, Size, Image, Category)
3: SalePerson (SalePersonID, Name, Designation, Shift, Address, Phone)
4: Outlets (OutletID, Address (Location), City, Working-hour, Active-Day, Total Employees)
5: *Order/Sale/Shopping (OrderID, CustomerFID, ProductFID,
SalePersonFID, OutletFID, Quantity, Date, Time, Amount, Payment
Mode, Status)

Relationship between Tables:


Product vs. Customer (Order => M – M)
Outlet vs. Customer (Order => M – M)
Outlet vs. Product (Order => M – M)

Rule: PKs of Both Tables will be putted in third table as FK.

Subject Table vs. Teacher Table (M - M)


1. Subject Table  3. TimeTable  2. Teacher Table
(M – 1 )  TimeTable  (1 – M)

Draw database of Voting System along with ER-


Diagram.
Table:
1. Voter (VoterID, Name, Age, CNIC, Area, …….)
2. Party (PartyID, Name, Chairman, Flag, Symbol)
3. Candidate (CandidateID, Name, Age, CNIC, Area, PartyFID)
4. *Vote (VoteID, VoterFID, CandidateFID, PollingStationFID, Date, Time)
5. Polling Station (PollingStationID, Number, Address, ….)
6. Polling Staff (StaffID, StaffName, Designation, PollingStationFID )

Party vs. Candidate (1 - M)


PollingStation Table vs. PollingStaff Table (1 - M)

STRUCTURED QUERY LANGUAGE.


A language to fetch information by asking different
type of queries from the structure of database.
 Normally software pick data from the database as information.
 Software is developed by using some Programming Language e.g. C,
C++, C#, Java, Php, Python….
 In software along with development language we also use SQL
Language to fetch information from the database.
 Programming Language is use to make software while SQL is use to
save or fetch information from database.
Query: (SQL is not case Sensitive you can use upper or lower
case)
SELECT (Single Column, Multi Column, All Column)
FROM (Table Name)
WHERE (apply conditions to fetch specific Records/Rows)
 Comparison Operators (= != > < >= <=)
 Logical Operators (AND, OR, NOT)
 Arithmetic Operators (+ - * / %)
 Top N, BETWEEN AND, LIKE, IN, IS
Group BY
Group Functions (Min, Max, Avg, Sum, Count)
ORDER BY (e.g CGPA ASC / DESC Ordering)
From Select now to => Delete + Update…..

Database Paper Pattern: (75 Marks)


30 Database Concept (Short Questions)
15 Marks (Create Database)
15 Marks (ER-Diagram (Entity-Relationship))
=> 15 Marks (SQL Statements)
15 Marks (??????? Normalization)

You might also like