Introduction to
Databases
Section 1
Eng. Mostafa Nafie
Databases are everywhere …
Traditional (SQL) Databases NoSQL Database
Databases are for everyone …
Backend Developer Mobile Application Developer Data Scientist
So … What’s a database?
● A database is a collection of data, typically describing
the activities of one or more related organizations.
● A database models some aspect of the real world.
● A database has some source from which data is derived,
some degree of interaction with events in the real world,
and an audience that interested in its contents.
● A database can be of any size or complexity.
Database Management System (DBMS)
● A database Management System (DBMS) is a
software that enables users to create, maintain, and
access databases.
● Its features allow us to manage the data in an efficient
and easy manner.
● An application program access the database by
sending queries or requests to the DBMS.
Why use DBMS ?!
Just store the data in a text file … simple and easy!
Data Redundancy
FirstName LastName DOB Fees FirstName LastName DOB Fees
Mohammed Samir 2003 3000 Mohammed Samir 2003 3000
Ahmed Farouk 2005 2000 ???? Ahmed Farouk 2005 2000
Amr Elsayed 2000 4000 Amr Elsayed 2000 4000
Students.txt Students.txt
Accounting Dept. Management
Data Redundancy FirstName
Mohammed
LastName
Samir
DOB
2003
Fees
3000
(Fixed) Ahmed Farouk 2005 2000
Amr Elsayed 2000 4000
Students.db
Accounting Dept. Management
FirstName LastName DOB Fees grade
Data Administration Mohammed Samir 2003 3000 A-
Ahmed Farouk 2005 2000 B
Amr Elsayed 2000 4000 A
Students.txt
FirstName LastName DOB Fees grade
Mohammed Samir 2003 3000 A-
Ahmed Farouk 2005 2000 B
Amr Elsayed 2000 4000 A
FirstName LastName DOB Fees grade
Mohammed Samir 2003 3000 A-
Ahmed Farouk 2005 2000 B
Accounting Dept. Amr Elsayed 2000 4000 A Teachers
Data Administration FirstName
Mohammed
LastName
Samir
DOB
2003
Fees
3000
grade
A-
(Fixed) Ahmed Farouk 2005 2000 B
Amr Elsayed 2000 4000 A
Students.db
FirstName LastName DOB grade
Mohammed Samir 2003 A-
Ahmed Farouk 2005 B
Amr Elsayed 2000 A
FirstName LastName DOB Fees
Mohammed Samir 2003 3000
Ahmed Farouk 2005 2000
Accounting Dept. Amr Elsayed 2000 4000 Teachers
Efficient Data Access
ID FirstName LastName DOB Fees Subject 1 Subject 2 Grade 1 Grade 2 ..
1 Mohammed Samir 2003 3000 Maths English A C ..
2 Ahmed Farouk 2005 2000 Chemistry French B A ..
3 Mostafa Nafie 1998 1000 Maths Physics A+ A+ ..
. . . . . . . . . ..
Students.txt
. . . . . . . . .
What subjects ..did
. . . . . . . . .
student ..
Amr take
. . . . . . . . . ? ..
. . . . . . . . . ..
. . . . . . . . . ..
. . . . . . . . . ..
. . . . . . . . . ..
. . . . . . . . . ..
5000 Amr Elsayed 2000 4000 History Physics A+ B+ ..
Efficient Data Access (Fixed)
Students.db subjects.db
ID FirstName LastName DOB Fees ID Subject 1 Subject 2 Grade 1 Grade 2
2 Ahmed Farouk 2005 2000 1 Maths English A C
5000 Amr Elsayed 2000 4000 2 Chemistry French B A
. . . . . 3 Maths Physics A+ A+
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
1 Mohammed Samir 2003 3000 . . . . .
3 Mostafa Nafie 1998 1000 . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . 5000 History Physics A+ B+
Concurrent Access
FirstName LastName DOB Fees
Mohammed Samir 2003 3000
AT THE SAME TIME !!!
Ahmed Farouk 2005 2000
2500
Amr Elsayed 2000
1998 4000
Students.txt
Corrupted Data !!!
Accounting Dept. Management
Concurrent Access FirstName
Mohammed
LastName
Samir
DOB
2003
Fees
3000
(Fixed) Ahmed Farouk 2005 2500
2000
Amr Elsayed 2000
1998 4000
Students.db
Accounting Dept. Management
Crash Recovery
ID Name Date Amount Final Balance Prev Balance
1 Mohammed 1/1/2024 -3000 10000 13000
2 Ahmed 1/1/2024 +3000 3400 400
3 Mostafa 1/7/2024 -500 5000 5500
4 Mahmoud 1/7/2024
Transactions.txt
Crash Recovery (Fixed)
ID Name Date Amount Final Balance Prev Balance
1 Mohammed 1/1/2024 -3000 10000 13000
2 Ahmed 1/1/2024 +3000 3400 400
3 Mostafa 1/7/2024 -500 5000 5500
4 Mahmoud 1/7/2024
Transactions.db
Data Integrity
ID FirstName LastName DOB Fees Subject 1 Subject 2 Grade 1 Grade 2 ..
1 Mohammed Samir 2003 3000 Maths English 3 C ..
2 Ahmed l -300 2000 Chemistry French B A ..
3 Mostafa Nafie 1998 1000 Maths Physics A+ A+ ..
. . . . . . . . . ..
Students.txt
. . . . . . . . . ..
. . . . . . . . . ..
. . . . . . . . . ..
. . . . . . . . . ..
. . . . . . . . . ..
. . . . . . . . . ..
. . . . . . . . . ..
. . . . . . . . . ..
5000 Amr Elsayed 2000 4000 History Physics A+ B+ ..
Data Security
ID FirstName LastName DOB Fees Subject 1 Subject 2 Grade 1 Grade 2 ..
1 Mohammed Samir 2003 3000 Maths English A C ..
2 Ahmed Farouk 2005 2000 Chemistry French B A ..
3 Mostafa Nafie 1998 1000 Maths Physics A+ A+ ..
. . . . . . . . . ..
Students.txt
. . . . . . . . . ..
. . . . . . . . . ..
. . . . . . . . . ..
. . . . . . . . . ..
. . . . . . . . . ..
. . . . . . . . . ..
. . . . . . . . . ..
. . . . . . . . . ..
5000 Amr Elsayed 2000 4000 History Physics A+ B+ ..
$ rm ./students.txt
Reduced Application Development time
How to allow multiple users to access the same file
simultaneously and solve the racing condition problem ?
How to sort the elements in a text file ?
How to perform crash recovery on a text file ?
You no longer have to think about these problems, your DBMS
will take care of it for you
Advantages of DBMS:
● Eliminated Data Redundancy:
A single repository maintains data and then accessed by various users. This reduces
storage space and removes conflicts.
● Data Independence:
Application programs are not exposed of the details of data representation and
storage.
● Efficient Data Access:
A DBMS offers a variety of sophisticated techniques to store and retrieve data
efficiently.
● Data Administration:
Offers centralized administration of data.
Advantages of DBMS (Continued):
● Concurrent Access:
A DBMS schedules concurrent accesses to data in such a manner that users can
think of the data as being accessed by one user at a time.
● Crash Recovery:
A DBMS protects users from effects of system failures by maintaining a log file.
● Data Integrity and Security:
The DBMS can enforce integrity constraints before storing data. It can also enforce
access controls that governs what data is visible to different classes of users.
● Reduced Application Development Time
DBMS Terminologies:
● Data Model:
A data model is a collection of concepts used for
describing data.
It hides many low-level storage details.
Most DBMSs today are based on the relational data
model.
● Schema:
It's a description of data in terms of a data model.
Levels of abstraction in a DBMS:
Data in a DBMS is described at three levels of
abstraction: conceptional, physical, and external.
● Conceptual Schema: describes the stored data in
terms of the data model of the DBMS.
● Physical Schema: specifies data storage details.
● External Schema: we can define different external
schemas to give customized access to different
users and groups
Popular DBMS:
Microsoft SQL server
● Microsoft SQL Server is a relational database
management system (RDBMS) developed by
Microsoft.
● As a database server, it is a software product with
the primary function of storing and retrieving data
as requested by other software applications which
may run either on the same computer or on another
computer across a network (including the Internet).
Structured Query Language (SQL)
● In the early 1970s, IBM developed SQL (Structured
Query Language) for use in its original relational
database product named System R.
● Other vendors started building their own database
systems and developed query languages based on the
standard SQL.
● SQL became a standard of the (ANSI), and of the (ISO).
● T-SQL is an extension to SQL used by Microsoft SQL
Server.
Now let’s install MS SQL Server
Install SQL Server 2012 step by step - YouTube
References
Fundamentals of Database Systems Database Management Systems
Ramez Elmasri, Shamkant Navathe Raghu Ramakrishnan, Johannes Gehrke