DBMS Week2
DBMS Week2
Lecture # 3-4
Instructor
Rida Ayesha
Lecture # 3-4 Agenda:
• Functions of a DBMS
o Data Dictionary Management, Data Storage Management, Security Management, Backup and Recovery
Management, etc.
• Data Models
o Conceptual, Logical & Physical Data Model
o Flat-file, Hierarchical, Network, Relational, ER Model, Object-Oriented & No-SQL Data Model
o Examples & Mappings of Data Models
• Database Languages
o Fourth-Generation Languages (4GLs)
o The Data Definition Language (DDL)
o The Data Manipulation Language (DML)
o The Data Control Language (DCL)
o The Transaction Control Language (TCL)
5. Concurrency Control
• Allows multiple users to access data simultaneously.
4
Introduction to Data Models
• Definition: A data model defines how data is structured, stored, and manipulated
in a database system.
5
Conceptual, Logical, and Physical Data Models
• Example:
o Entities: Student, Course, Enrollment
o Relationships: A Student enrolls in a Course.
6
Conceptual, Logical, and Physical Data Models
(cont.)
2. Logical Data Model
• Example:
o Student Table: Student_ID (PK), Name, Age
o Course Table: Course_ID (PK), Title
o Enrollment Table: Enrollment_ID (PK),
Student_ID (FK), Course_ID (FK)
7
Conceptual, Logical, and Physical Data Models
(cont.)
3. Physical Data Model
• Example:
CREATE TABLE Student (
Student_ID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT
);
8
Comparison of Conceptual, Logical & Physical
Data Models
9
Data Modeling Techniques
1. Flat-file
2. Hierarchical Model
3. Network Model
4. Relational Model
5. Entity-Relationship (E-R) Model
6. Object-Oriented Model
7. NoSQL Models (Document,
Key-Value, Column-Family,
Graph)
10
Flat File Data Model
11
Hierarchical Data Model
• Example Structure:
o Bank Branch → Accounts → Transactions
12
Network Data Model
• Example Structure:
o Flights ↔ Passengers
13
Relational Data Model
• Example Structure:
o Customers (Table) → Orders (Table)
→ Products (Table)
14
Entity-Relationship (E-R) Model
• Example Structure:
o Entities: Student, Course, Enrollment
o Relationships: "Student enrolls in
Course“
15
Object-Oriented Data Model
• Example Structure:
o Objects: Employee (Attributes: Name, Age,
Salary)
o Inheritance: Manager (inherits from
Employee)
17
Types of NoSQL Data Models
18
Comparison of NoSQL Types
Scales with
Scalability Horizontal High horizontal Highly scalable
relationships
19
Comparison of Data Models
20
Examples & Mappings of Data Models
21
Examples & Mappings of Data Models (cont.)
22
Examples & Mappings of Data Models (cont.)
23
Examples & Mappings of Data Models (cont.)
24
Examples & Mappings of Data Models (cont.)
25
Examples & Mappings of Data Models (cont.)
26
Examples & Mappings of Data Models (cont.)
• The following diagram represents a network data model that shows that the Stores
entity has relationship with multiple child entities and the Transactions entity has
relationships with multiple parent entities. In other words, a network database
model allows one parent to have multiple child record sets and each record set can
be linked to multiple nodes (parents) and children.
27
Examples & Mappings of Data Models (cont.)
28
Examples & Mappings of Data Models (cont.)
29
Examples & Mappings of Data Models (cont.)
OO
30
Examples & Mappings of Data Models (cont.)
OO
31
Examples & Mappings of Data Models (cont.)
32
Examples & Mappings of Data Models (cont.)
33
Fourth-Generation Languages (4GLs)
Definition:
• Fourth-Generation Languages (4GLs) are high-level programming languages
designed to be more user-friendly and efficient than traditional procedural
languages (3GLs).
34
Key Features of Fourth-Generation Languages
(4GLs)
• High-Level Abstraction – Users specify "what" to do rather than "how" to do
it.
• Less Coding Required – Compared to 3GLs (C, Java), 4GLs require fewer lines
of code.
35
Key Features of Fourth-Generation Languages
(4GLs)
• Examples of 4GLs are SQL for Data Base, Python for Scripting and PHP for
Web development
36
Database Languages
• In the data world, we need some special kind of programming languages to make
the DBMS software understand our needs and manage the data stored in the
databases accordingly. These programming languages are known as database
languages or query languages.
• Database languages are used to perform a variety of critical tasks that help a
database management system function correctly. These tasks can be certain
operations such as read, update, insert, search, or delete the data stored in the
database.
37
Types of Database Languages
• The Data Languages are categorized into four different types based upon the
various operations performed by the language. These include:
38
1. Data Definition Language (DDL)
• Data Definition Language (DDL) is a set of special commands that allows us to
define and modify the structure and the metadata of the database. These
commands can be used to create, modify, and delete the database structures such
as schema, tables, indexes, etc.
• Since DDL commands can alter the structure of the whole database and every
change implemented by a DDL command is auto-committed (the change is saved
permanently in the database), these commands are normally not used by an end-
user (someone who is accessing the database via an application).
• Commands:
o CREATE – Creates database objects (tables, indexes, etc.).
o ALTER – Modifies an existing database structure.
o DROP – Deletes database objects.
o TRUNCATE – Removes all records from a table (without logging individual deletions).
39
1. Data Definition Language (DDL) – (cont.)
1. CREATE:
• It is used to create the database or its schema objects.
40
1. Data Definition Language (DDL) – (cont.)
2. DROP:
• It is used to delete the database or its schema objects.
41
1. Data Definition Language (DDL) – (cont.)
3. ALTER:
• It is used to modify the structure of the database objects.
42
1. Data Definition Language (DDL) – (cont.)
4. TRUNCATE:
• It is used to remove the whole content of the table along with the
deallocation of the space occupied by the data, without affecting the
table's structure.
• NOTE - We can also use the DROP command to delete the complete table, but the
DROP command will remove the structure along with the contents of the table.
• Hence, if you want to remove the data present inside a table but not the table
itself, you can use TRUNCATE instead of DROP.
43
2. Data Manipulation Language (DML)
• Data Manipulation Language (DML) is a set of special commands that allows us
to access and manipulate data stored in existing schema objects. These
commands are used to perform certain operations such as insertion, deletion,
updating, and retrieval of the data from the database.
• These commands deal with the user requests as they are responsible for all
types of data modification. The DML commands that deal with the retrieval of
the data are known as Data Query language.
• NOTE: The DML commands are not auto-committed i.e., the changes and
modifications done via these commands can be rolled back.
• Commands:
o SELECT – Retrieves data.
o INSERT – Adds new records.
o UPDATE – Modifies existing records.
o DELETE – Removes records. 44
2. Data Manipulation Language (DML)
1. SELECT
• It is used to retrieve or fetch data from a database. The SELECT
statement cannot manipulate data, it can only access it. Hence, it is
known as the Data Query Language, i.e., a limited form of DML
statement.
2. INSERT
• It is used to insert new rows into the table.
• Note: While using the INSERT command, make sure that the
datatypes of each column match with the inserted value, as this may
lead to unexpected scenarios and errors in the database.
46
2. Data Manipulation Language (DML) – (cont.)
3. UPDATE
• It is used to update existing column(s)/value(s) within a table.
• Note: Here, the SET statement is used to set new values to the
particular column, WHERE clause is used to select rows for
which the columns are updated for the given table.
47
2. Data Manipulation Language (DML) – (cont.)
4. DELETE
• It is used to delete existing records from a table, i.e., it is used to
remove one or more rows from a table.
• Note: The DELETE statement only removes the data from the table,
whereas the TRUNCATE statement also frees the memory along with
data removal. Hence, TRUNCATE is more efficient in removing all the
data from a table.
48
3. Data Control Language (DCL)
• Data Control Language (DCL) is a set of special commands that are used to
control the user privileges in the database system. The user privileges include
ALL, CREATE, SELECT, INSERT, UPDATE, DELETE, EXECUTE, etc.
1. Grant:
• It is used to provide user access to the database or its objects.
2. Revoke:
• It is used to revoke user access to the database system.
1. COMMIT:
• It is used to permanently save all the modifications are done (all the
transactions) by the DML commands in the database. Once issued, it
cannot be undone.
• It restores the previously stored value, i.e., the data present before
the execution of the transactions.
3. SAVEPOINT:
51
4. Transaction Control Language (TCL) – (cont.)
BEGIN;
UPDATE Students SET Age = 22 WHERE ID = 2;
SAVEPOINT save1;
DELETE FROM Students WHERE ID = 3;
ROLLBACK TO save1; -- Undo the DELETE operation
COMMIT;
52
Database
Architecture &
Environment
53
The Three-Level ANSI-SPARC Architecture
• The ANSI-SPARC (American National Standards Institute – Standards Planning And
Requirements Committee) architecture defines a three-level database structure to
ensure data abstraction, security, and independence.
• It separates user views, logical structure, and physical storage to make databases
more flexible and manageable.
54
The Three-Level ANSI-SPARC Architecture (cont.)
55
Three-Level of ANSI-SPARC Architecture
• The highest level, defining how individual users or applications see the data.
• Different views can be created for different users based on their needs.
• Example: A student may see only their own grades, while an admin sees all
student records.
56
Three-Level of ANSI-SPARC Architecture (cont.)
• The middle level, describing what data is stored and how it is organized.
57
Three-Level of ANSI-SPARC Architecture (cont.)
• The lowest level, detailing how data is physically stored in memory (files,
indexes, blocks).
58
Advantages of Three-Level ANSI-SPARC
Architecture
• Data Abstraction & Independence – Users don’t need to know how data is
stored.
• Security & Access Control – Different users get different views of data.
59
Schemas, Mappings & Instances
• Types of Schemas:
• External Schema – User-specific views of the database.
• Conceptual Schema – Logical structure of the entire database.
• Internal Schema – Physical storage details.
Example:
• A university database schema defines tables: Students, Courses, Enrollments
with attributes like Student_ID, Course_Name, Marks.
60
Schemas, Mappings & Instances (cont.)
Example:
• Schema (Structure): Student(ID, Name, Age).
• Instance (Data at a moment)
(101, Alice, 20)
(102, Bob, 21)
• If Alice’s age is updated to 21, the schema remains the same, but the instance
changes.
61
Schemas, Mappings & Instances (cont.)
Types of Mappings:
• External-Conceptual Mapping – Connects user views to logical structure.
• Conceptual-Internal Mapping – Defines how logical data is stored physically.
Example:
• A conceptual table Students(ID, Name, Age) is stored as indexed files in the
internal schema.
• Mapping defines this storage process.
62
Types of Data Independence
63
Types of Data Independence (cont.)
Definition:
• The ability to change the conceptual schema (logical structure) without
affecting external schemas (user views).
• Ensures that applications don’t need modification when changes are made to
the database structure.
Examples:
• Adding a new column to a table (e.g., adding "Email" to "Students" table).
• Splitting a table into two related tables.
• Merging two tables into one table.
64
Types of Data Independence (cont.)
• The external schema (user views) remains unchanged, and only new applications or modified
views will make use of the new column.
65
Types of Data Independence (cont.)
Suppose a Student table is split into Students (ID, Name, Age) and ContactInfo (ID, Email,
Phone).
• The UI still fetches student data the same way using a view that joins both tables.
• Applications don’t need modification, so Logical Data Independence is maintained.
66
Types of Data Independence (cont.)
Definition:
• The ability to change the internal schema (storage details) without affecting
the conceptual schema.
• Ensures that the logical structure remains unchanged even if storage methods
are modified.
Examples:
• Changing storage format (e.g., from B-tree indexing to Hashing).
• Moving data from one disk to another.
• Compressing or partitioning a large table.
67