Lesson2
Lesson2
Data Models
A data model is a set of concepts and rules that describe the
structure of a database, as well as its operations and constraints. It
allows for better organization, access, and retrieval of data while
ensuring consistency and integrity.
Categories of Data Models
1. Conceptual Models:
Represent data in a way that is close to how users perceive it.
Example: Entity-Relationship (E-R) Model.
Used mainly in database design to create a high-level representation
of the data structure.
Practical Example:
3. Physical Models:
Describe how data is stored and organized at the hardware level.
Include storage structures like files and data blocks.
Define strategies for efficient data access and retrieval.
Use indexes to optimize queries and improve search performance.
Example of using indexes for performance improvement:
CREATE INDEX idx_name ON Student(Name);
Indexes are essential in relational databases because they reduce
the time required for searching data, especially in large datasets.
Without indexes, the database must scan entire tables to locate
records.
4. Self-Descriptive Models:
Mix data with its description (metadata).
Example: XML, JSON, NoSQL.
Practical Example in JSON:
{
"ID": 1,
"Name": "Carlos",
"Surname": "Gomez",
"Major": "Engineering"
}
JSON databases, such as MongoDB, allow flexible and scalable storage
solutions, especially for web applications.
Three-Tier Architecture
1. Internal Level: Defines the physical storage structure.
2. Conceptual Level: Describes the logical organization of the
database.
3. External Level: Provides different views for users.
Data Independence
Logical Independence: Changes in the conceptual schema
without affecting applications.
Physical Independence: Changes in storage without affecting
the logical structure.
Example in SQL
ALTER TABLE Client ADD Phone VARCHAR(15);
This modification adds a new column to the table without altering
existing applications or queries.
Database Languages
1. DDL (Data Definition Language):
Defines the database structure. Used for creating and modifying tables.
Query Optimization
Modern databases include optimization mechanisms such as:
Query Planning: Choosing the best execution method.
Caching: Storing results of frequent queries.
Parallelization: Splitting queries into multiple processes.
Database Architectures
Centralized: A single server manages the database.
Two-Tier Client/Server:
Client handles the interface.
Server manages the database.
Three-Tier Client/Server:
An application server is introduced.
Distributed Systems:
Data is distributed across multiple servers.
Database Management System (DBMS) Tools and Utilities
Backup and recovery.
Performance monitoring.
Query optimization.
Metadata management.
Example of Backup in MySQL: