0% found this document useful (0 votes)
5 views67 pages

DBMS Week2

The document outlines the functions of a Database Management System (DBMS), including data storage, security, integrity, and backup management. It discusses various data models such as conceptual, logical, and physical models, along with different database languages like DDL, DML, DCL, and TCL. Additionally, it compares various data models, including relational and NoSQL, highlighting their structures, best use cases, and limitations.

Uploaded by

cindrella23401
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views67 pages

DBMS Week2

The document outlines the functions of a Database Management System (DBMS), including data storage, security, integrity, and backup management. It discusses various data models such as conceptual, logical, and physical models, along with different database languages like DDL, DML, DCL, and TCL. Additionally, it compares various data models, including relational and NoSQL, highlighting their structures, best use cases, and limitations.

Uploaded by

cindrella23401
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

Database Systems (CC-230)

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)

• Database Architecture & Environment


o The Three-Level ANSI-SPARC Architecture
▪ External Level / Layer (View Level)
▪ Conceptual Level / Layer (Logical Level)
▪ Internal Level / Layer (Physical Level)
o Schemas, Mapping & Instances
o Types of Data Dependence
▪ Physical & Logical Data Dependence
2
Functions of a DBMS
We look at the types of function and service that we would expect a DBMS to
provide.
1. Data Storage, Retrieval & Management
• Stores large volumes of structured data efficiently.
• Allows quick retrieval and updates using SQL queries.

2. Data Security & Access Control


• Ensures authentication & authorization (user permissions).
• Protects against unauthorized access & data breaches.

3. Data Integrity & Consistency


• Enforces constraints (e.g., primary key, foreign key).
• Prevents duplicate, missing, or invalid data.

4. Data Dictionary Management


• The DBMS maintains a data dictionary, which is a repository of metadata (data about
data).
• It stores information about tables, columns, data types, relationships, constraints,
indexes, and user privileges.
• Helps in database organization, consistency, and security.
3
Functions of a DBMS (cont.)

5. Concurrency Control
• Allows multiple users to access data simultaneously.

6. Backup & Recovery


• Automates data backups to prevent data loss.
• Restores databases in case of system failures.

7. Data Abstraction & Independence


• Separates logical & physical data storage.
• Applications remain unaffected by database structure changes.

8. Query Processing & Optimization


• Analyzes SQL queries to improve execution speed.
• Uses indexing & caching to optimize performance.

4
Introduction to Data Models

• Definition: A data model defines how data is structured, stored, and manipulated
in a database system.

• Importance: Helps design an organized and efficient database structure.

5
Conceptual, Logical, and Physical Data Models

1. Conceptual Data Model

• Purpose: High-level, abstract view of data


without technical details.

• Focus: Entities, relationships, and business


rules.

• Example:
o Entities: Student, Course, Enrollment
o Relationships: A Student enrolls in a Course.

• Used By: Business analysts, stakeholders,


database designers.

6
Conceptual, Logical, and Physical Data Models
(cont.)
2. Logical Data Model

• Purpose: Converts the conceptual model into a


structured format.

• Focus: Attributes, primary keys, foreign keys,


and normalization.

• 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)

• Used By: Database designers, architects.

7
Conceptual, Logical, and Physical Data Models
(cont.)
3. Physical Data Model

• Purpose: Implements the logical model in a specific


database system.

• Focus: Table structures, data types, indexes, constraints,


storage optimization.

• Example:
CREATE TABLE Student (
Student_ID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT
);

• Used By: Database administrators (DBAs), developers.

8
Comparison of Conceptual, Logical & Physical
Data Models

Model Purpose Focus Users Example


High-level data Entities & Business analysts, Student ↔
Conceptual
abstraction relationships stakeholders Course
Converts conceptual
Attributes, keys, Database Tables & keys
Logical model into structured
normalization designers defined
format
Implements logical Data types, SQL schema,
Physical DBAs, developers
model in DBMS indexes, storage indexes

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

• A simple, two-dimensional structure for storing


data.

• Data is stored in a single table (text file, CSV, or


spreadsheet).

• No structured relationships (all data stored in one large table).

• Limited indexing and searching capabilities.

• Data redundancy and inconsistency issues.

• Used in small-scale applications, configuration files, log files.

11
Hierarchical Data Model

• Structure: Tree-like (Parent-Child relationship).

• Example Database: IBM IMS

• Use Case: Banking systems, file systems

• Example Structure:
o Bank Branch → Accounts → Transactions

• Pros: Fast access, efficient for one-to-many relationships.

• Cons: Rigid structure, difficult to modify.

12
Network Data Model

• Structure: Graph-based (Many-to-Many, Many-to-one relationships).

• Example Database: IDS (Integrated Data Store), CA-IDMS (Integrated


Data Management System)

• Use Case: Airline reservation systems, telecommunications

• Example Structure:
o Flights ↔ Passengers

• Pros: More flexible than hierarchical models.

• Cons: Complex relationships, difficult to manage.

13
Relational Data Model

• Structure: Tables (Rows & Columns) with relationships.

• Example Database: MySQL, PostgreSQL, Oracle, SQL Server

• Use Case: Business applications, e-commerce, finance

• Example Structure:
o Customers (Table) → Orders (Table)
→ Products (Table)

• Pros: Easy to use, widely adopted.

• Cons: Performance issues for very


large datasets.

14
Entity-Relationship (E-R) Model

• Structure: Uses entities, attributes, and relationships.

• Example Database: Used for designing databases before implementing in


RDBMS like MySQL, Oracle

• Use Case: University database, hospital management systems

• Example Structure:
o Entities: Student, Course, Enrollment
o Relationships: "Student enrolls in
Course“

• Pros: Clear conceptual design, helpful in


planning.

• Cons: Needs conversion into relational


format.

15
Object-Oriented Data Model

• Structure: Stores data as objects (like OOP


concepts).

• Example Database: db4o, ObjectDB, Versant

• Use Case: Multimedia databases, CAD


systems, AI applications

• Example Structure:
o Objects: Employee (Attributes: Name, Age,
Salary)
o Inheritance: Manager (inherits from
Employee)

• Pros: Supports complex data types, real-


world modeling.

• Cons: Less commonly used than relational databases.


16
NoSQL Data Models

The term NoSQL, short for “not only SQL,”


refers to non-relational databases that store
data in a non-tabular format, rather than in
rule-based, relational tables like relational
databases do.

• Structure: Flexible, schema-less (JSON,


key-value pairs).

• Example Database: MongoDB (Document-


oriented), Redis (Key-value store).

• Pros: Scalable, handles big data efficiently.

• Cons: Lacks standardization, not suitable


for all applications.

17
Types of NoSQL Data Models

18
Comparison of NoSQL Types

Document- Key-Value Column-


Feature Based Store Oriented Graph-Based
JSON-like Columns Nodes &
Data Model Key-Value pairs
documents instead of rows Relationships

Semi-structured Fast lookups & Analytics & big Relationship-


Best Use Case
data caching data heavy data

Query High for Optimized for


Moderate Fast
Performance analytics relationships

Schema Flexible Dynamic Semi-structured Schema-less

Scales with
Scalability Horizontal High horizontal Highly scalable
relationships

MongoDB, Redis, Cassandra, Neo4j, Amazon


Example DB
CouchDB DynamoDB HBase Neptune

19
Comparison of Data Models

Model Structure Best For Limitations


Hierarchical Tree One-to-many relationships Rigid structure
Network Graph Complex relationships Difficult to manage
Relational Tables General-purpose applications Performance issues
Needs conversion to
E-R Conceptual Database design
RDBMS
Object- Multimedia, OOP-based
Objects Less common
Oriented applications
NoSQL Schema-less Big data, scalable applications Lack of standardization

• Different data models are suited for different types of applications.


• Relational models dominate traditional databases, while NoSQL models are
used for big data.
• Choosing the right data model depends on application needs.

20
Examples & Mappings of Data Models

21
Examples & Mappings of Data Models (cont.)

Guess the model?


• Lets say we have few students and few courses and a course can be assigned to a
single student only, however a student take any number of courses so this
relationship becomes one to many.

22
Examples & Mappings of Data Models (cont.)

Guess the model?

23
Examples & Mappings of Data Models (cont.)

ER and Hierarchical Models

24
Examples & Mappings of Data Models (cont.)

Guess the Model?

25
Examples & Mappings of Data Models (cont.)

Hierarchical Model and Relational Model

26
Examples & Mappings of Data Models (cont.)

Network Data Model

• 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.)

Relational and hierarchical

28
Examples & Mappings of Data Models (cont.)

Object-Oriented and Relational

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).

• They focus on reducing code complexity and increasing productivity by using


declarative, non-procedural syntax.

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.

• Easier Database Interaction – Optimized for data manipulation, reporting,


and query processing.

• Graphical and Declarative – Some 4GLs use visual programming interfaces.

• Rapid Application Development (RAD) – Speeds up software development.

35
Key Features of Fourth-Generation Languages
(4GLs)

• SQL (Structured Query Language) – Used for database queries.


• Report Generators – Crystal Reports, Oracle Reports.
• Spreadsheets & BI Tools – Excel macros, Power BI.
• AI & Machine Learning Tools – MATLAB, R.

• 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.

• Database Language is a special type of programming language used to define and


manipulate a 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:

• DDL (Data Definition Language) – Defines database structure.


• DML (Data Manipulation Language) – Handles data operations.
• DCL (Data Control Language) – Manages permissions.
• TCL (Transaction Control Language) – Manages transactions.

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).

• Some of the DDL commands are:

• 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.

• SQL Syntax - To create a new database:


CREATE DATABASE database_name;

• SQL Syntax - To create a new table:


CREATE TABLE table_name ( column_1 DATATYPE, column_2 DATATYPE, column_n
DATATYPE );

40
1. Data Definition Language (DDL) – (cont.)

2. DROP:
• It is used to delete the database or its schema objects.

• SQL Syntax - To delete an object:


DROP object object_name

• SQL Syntax - To delete an existing table:


DROP TABLE table_name;

• SQL Syntax - To delete the whole database:


DROP DATABASE database_name;

41
1. Data Definition Language (DDL) – (cont.)

3. ALTER:
• It is used to modify the structure of the database objects.

• SQL Syntax - To add new column(s) in a table:


ALTER TABLE table_name ADD ( column_1 DATATYPE, column_2 DATATYPE,
column_n DATATYPE );

• SQL Syntax - To change the datatype of a column in a table:


ALTER TABLE table_name ALTER COLUMN column_name new_data_type;

• SQL Syntax - To remove a column from a table:


ALTER TABLE table_name DROP COLUMN column_name;

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.

• SQL Syntax - To remove data present inside a table:


TRUNCATE TABLE table_name;

• 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.

• Some of the DML commands are:

• 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.

• SQL Syntax - To fetch an entire table:


SELECT * FROM table_name;

• SQL Syntax - To fetch particular columns from a table:


SELECT column_1, column_2 FROM table_name;

• SQL Syntax - To fetch particular columns from a table based on a condition:


SELECT column_1, column_2 FROM table_name WHERE <condition>;

• SQL Syntax - Fetching data with various clauses (General SELECT


statement):
SELECT column_list FROM table-name [WHERE Clause] [GROUP BY clause]
[HAVING clause] [ORDER BY clause];
45
2. Data Manipulation Language (DML) – (cont.)

2. INSERT
• It is used to insert new rows into the table.

• SQL Syntax - To insert values according to the table structure:


INSERT INTO table_name VALUES value1, value2, value3;

• SQL Syntax - To insert values based on the columns:


INSERT INTO table_name column1, column2, column3 VALUES value1,
value2, value3;

• 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.

• SQL Syntax - To update the columns of a table based on a condition


(General UPDATE statement):
UPDATE table_name SET column_1 = value1, column_2 = value2,
column_3 = value3, [WHERE condition]

• 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.

• SQL Syntax - To delete rows from a table based on a condition:

DELETE FROM table_name [WHERE condition];

• 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.

• We require data access permissions to execute any command or query in the


database system. This user access is controlled using the DCL statements. These
statements are used to grant and revoke user access to data or the database.

• DCL commands include:

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.

• SQL Syntax - To grant & revoke permissions to a user:


GRANT SELECT, INSERT ON Students TO user1;
REVOKE INSERT ON Students FROM user1;
49
4. Transaction Control Language (TCL)
• Transaction Control Language (TCL) is a set of special commands that deal with
the transactions within the database. A transaction is a collection of related
tasks that are treated as a single execution unit by the DBMS software. Hence,
transactions are responsible for the execution of different tasks within a
database.

• The modifications performed using the DML commands are executed or


rollbacked with the help of TCL commands. These commands are used to keep
a check on other commands and their effects on the database. These include:

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.

• DBMS software implicitly uses the COMMIT command before and


after every DDL command to save the change permanently in the
database.
50
4. Transaction Control Language (TCL) – (cont.)
2. ROLLBACK:
• It is used to undo the transactions that have not already been
permanently saved (or committed) to the database.

• It restores the previously stored value, i.e., the data present before
the execution of the transactions.

3. SAVEPOINT:

• It is used to create a point within the groups of transactions to save or


roll back later.

• It is used to roll the transactions back to a certain point without the


need to roll back the whole group of transactions.

51
4. Transaction Control Language (TCL) – (cont.)

• SQL Syntax – For save point, rollback & commit:

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.

• Following are the three levels.

1. External Level / Layer (View Level)


2. Conceptual Level / Layer (Logical Level)
3. Internal Level / Layer (Physical Level)

54
The Three-Level ANSI-SPARC Architecture (cont.)

55
Three-Level of ANSI-SPARC Architecture

1. External Level / Layer (User View)

• 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.)

2. Conceptual Level / Layer (Logical View)

• The middle level, describing what data is stored and how it is organized.

• It represents the entire database structure but hides physical details.

• Example: The ER model of a university database showing students, courses,


and enrollments.

57
Three-Level of ANSI-SPARC Architecture (cont.)

3. Physical Level / Layer (Physical View)

• The lowest level, detailing how data is physically stored in memory (files,
indexes, blocks).

• Optimized for storage efficiency and performance.

• Example: A student’s record is stored as binary data in a specific disk sector.

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.

• Easier Maintenance & Scalability – Changes at one level don’t affect


others.

59
Schemas, Mappings & Instances

1. Schema (Database Structure)

• Definition: A schema defines the structure of a database, including tables,


attributes, and relationships.

• It remains constant unless modified by a database administrator.

• 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.)

2. Instance (Database Snapshot)

• Definition: A database instance represents the actual data stored in the


database at a given moment.

• Dynamic – Changes frequently as users insert, update, delete data.

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.)

3. Mappings (Schema Linkage)

• Definition: Mappings define how data is transformed and stored across


different schema levels.

• Ensures data abstraction by connecting external, conceptual, and internal


schemas.

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

• The major objective for the three-level architecture is to provide data


independence, which means that the upper levels are unaffected by changes to
lower level.

There are two types of data independence:


1. Logical Data Independence
2. Physical Data Independence

63
Types of Data Independence (cont.)

1. Logical Data Independence

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.)

Understanding Logical Data Independence

Case 1: Adding a New Column (Email)

Scenario where Logical Data Independence is maintained:


• If you add a new column (Email) but do not force existing applications to use it, then existing
applications can continue working without modification.

• The external schema (user views) remains unchanged, and only new applications or modified
views will make use of the new column.

Scenario where Logical Data Independence is broken:


• If your UI or application must now display or require the Email field, then the external schema
must be updated, which means Logical Data Independence is not fully achieved in this case.

65
Types of Data Independence (cont.)

Understanding Logical Data Independence

Case 2: Splitting or Merging Tables

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.)

2. Physical Data Independence

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

You might also like