Database
Database
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 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
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)
1. Full backup
2. Incremental 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.
Relationship:
Class vs. Teacher (M – M => Timetable)
Class vs. Subject (M – M => Timetable)
Teacher vs. Subject (M – M => Timetable)