Comprehensive Guide to Database Management Systems

Database Management Systems Fundamentals

A database is a structured computer framework designed for storing data in a shared and integrated manner, allowing data to be transformed into information as required. Data refers to raw facts, while information is processed data that reveals the underlying meaning of those facts.

Components of a Database
  • Tables: A collection of related records.

  • Fields (Columns): A single category of data stored in the database, such as a name or telephone number.

  • Records (Rows): A collection of related fields representing a single entity, such as all fields pertaining to one customer.

Transforming Raw Data into Information

Data transition follows a specific pipeline: raw facts are entered into a form, stored as raw data, and then summarized. For instance, reading through hundreds of faculty rows is inefficient, but summarizing that data allows for specific inquiries, such as determining that 20%20\% of faculty members are adjunct professors. Visual aids like pie charts are often employed to represent these summaries for rapid comprehension.

Database Management Systems (DBMS)

A DBMS is a collection of programs used to manage the database structure and control access to stored data. It functions like an organized electronic filing cabinet. The DBMS provides end-users and application programs with a single, integrated view of the data. All application requests are intercepted by the DBMS, which converts them into complex operations to fulfill the request.

Applications of Database Systems

Database systems are utilized in various electronic applications, including:

  • Banking applications.

  • Credit and debit card transactions.

  • Social media applications (e.g., Facebook).

  • Point of Sale (POS) applications.

  • Library management applications.

  • School management applications.

Purpose of Database Systems

Database systems are designed to handle large volumes of data while providing mechanisms for modification and ensuring data safety. Key purposes include:

  • Managing very large amounts of data.

  • Supporting efficient access to large datasets.

  • Supporting concurrent access by multiple users.

  • Supporting secure, atomic access to data, ensuring integrity even during system crashes or unauthorized access attempts.

Actors within Database Systems

Users are categorized into five types based on their primary responsibilities:

  • System Administrators: Responsible for the overall operation of the database system.

  • Database Administrators (DBAs): Responsible for the DBMS and ensuring the database performs efficiently.

  • Database Designers: Act as database architects, designing the structure of the database.

  • System Analysts and Programmers: Develop application programs, including data entry screens, reports, and procedures for accessing or changing data.

  • End-users: People who use applications daily to run business operations. This includes sales clerks, supervisors, and managers. High-level end-users use the data for tactical and strategic decision-making.

Database Engines

A database engine is the core system that enables a database to function, specifically the part responsible for storing and retrieving data. Common engines include Oracle, MySQL, Microsoft SQL Server, and MariaDB.

Database System Concepts and Architecture

Schemas, Instances, and Data Models
  • Database Schema: The blueprint of the database created before it exists. It represents the logical view, defining parts and their relationships. A schema typically contains no data.

  • Database Instance: A snapshot of a fully operational database at a specific point in time, containing actual data. Instances change as data is added or modified.

  • Data Models: Graphical representations of data structures, properties, relationships, and constraints. For example, a relational model organizes data into tables.

Database Languages

A DBMS provides specific languages for interaction:

  • Data Definition Language (DDL): Commands used to create database objects like tables.

  • Data Manipulation Language (DML): Commands used for inserting, updating, deleting, and retrieving data.

  • Data Control Language (DCL): Commands to grant or revoke user access privileges.

  • Transaction Control Language (TCL): Commands to manage transactions. Key statements include:

    • Commit: Finalizes a transaction.

    • Rollback: Restores a transaction to a previous state if it fails.

DBMS Interfaces

Interfaces allow users to query databases without deep technical knowledge:

  • Menu-based Interfaces: Users select options from a list (e.g., web browser results).

  • Forms-based Interfaces: Users fill out form structures (e.g., online exam forms).

  • Graphical User Interfaces (GUI): Options are displayed as icons or buttons.

  • Natural Language Interfaces: Interpret requests written in languages like English.

  • DBA Interfaces: Specialized commands for account creation and system modification.

The Database Environment

A database system comprises five major components:

  • Hardware: Computers (PCs, servers, supercomputers), storage devices, network devices (hubs, routers), and peripherals.

  • Software: Includes the Operating System, DBMS software, and application programs.

  • People: All categories of users from administrators to end-users.

  • Procedures: Rules and instructions governing design and usage.

  • Data: The collection of facts stored within the system.

Database Architectures
  • 11-Tier Architecture: Client, server, and database exist on a single computer (e.g., local SQL practice).

  • 22-Tier Architecture: A presentation layer runs on a client device while data is stored on a server. This is more secure and facilitates faster, direct communication.

  • 33-Tier Architecture: Contains reaching three layers:

    • Presentation Layer: The user device (PC, Tablet).

    • Application Layer (Server): Houses business logic, checks for constraints, and handles requests between the user and the DBMS.

    • Database Server: Stores the data.

Classification of DBMS by Data Model
  • Relational Database (RDBMS): Organizes data into two-dimensional tables with rows and columns (e.g., MySQL, Oracle). Attributes (columns) like StudIDStudID act as primary keys.

  • Object-oriented Database: Combines relational ideas with object-oriented programming, storing data as objects.

  • Hierarchical Database: Data is organized in a tree structure (1:N1:N relationship). Examples include IBM IMS and the Windows registry.

  • Network Database: Data elements have many-to-many (N:NN:N) relationships, represented as a graph where a child record can have multiple parents.

  • Document-based Database: Handles "documents" instead of strict tables. Useful for data sets with no fixed length.

  • Graph-based Database: Specialized for creating and manipulating graphs (nodes and edges).

  • Column-based DBS: Stores data tables by column rather than row, allowing for faster subset querying and compression.

  • Key-value Database: Stores associative arrays (dictionaries/hash tables) retrieved via unique keys.

Database Modeling and Design

The Design Process and Life Cycles

Database design is part of the Systems Development Life Cycle (SDLC), a continuous process of system creation and maintenance. The Database Life Cycle (DBLC) involves six phases:

  1. Database initial study.

  2. Database design (Conceptual, Logical, and Physical).

  3. Implementation and loading.

  4. Testing and evaluation.

  5. Operation.

  6. Maintenance and evolution.

Levels of Design
  • Conceptual Design: The overall data view as seen by the end-user.

  • Logical Design: The data view as organized for the DBMS.

  • Physical Design: The data as managed by the operating system's storage devices.

Entity-Relationship (ER) Model

The ER model lists entities, attributes, and relationships with descriptions, data types, and constraints.

  • Entities: Represented by rectangles in ER diagrams (ERD).

  • Attributes: Characteristics of entities. Composite attributes comprise smaller parts (Address = Street + City), while simple attributes do not. Primary keys are unique identifying attributes.

  • Relationships: Represented by diamond shapes.

    • 1:11:1: One-to-one (e.g., one car engine to one serial number).

    • 1:N1:N: One-to-many (e.g., one person has multiple credit cards).

    • M:NM:N: Many-to-many (e.g., many customers buy many products).

Normalization

Normalization minimizes data redundancy and prevents anomalies. It follows stages called Normal Forms (NF):

  • First Normal Form (1NF1NF): Data is in a tabular format, no repeating groups, and a primary key is identified.

  • Second Normal Form (2NF2NF): Meets 1NF1NF requirements and contains no partial dependencies (attributes depend on the whole primary key).

  • Third Normal Form (3NF3NF): Meets 2NF2NF requirements and contains no transitive dependencies (attributes depend only on the primary key).

Normalization Procedure
  1. Step 11: Eliminate Repeating Groups: Ensure each cell has a single value.

  2. Step 22: Identify Primary Key: Determine the unique identifier (often a combination of fields, like PROJ_NUMPROJ\_NUM + EMP_NUMEMP\_NUM).

  3. Step 33: Identify All Dependencies: Map how attributes follow the primary key or other attributes (e.g., JOB_CLASS→CHG_HOURJOB\_CLASS \rightarrow CHG\_HOUR).

Step-by-Step ERD Creation in Microsoft Visio
  1. Start Microsoft Visio.

  2. Select the Database category and choose Crow’s Foot Database Notation.

  3. Click Create.

  4. Navigate to the VIEW tab and set Zoom to 100%100\%.

  5. Drag an Entity object to the grid.

  6. Double-click Entity Name and rename it (e.g., COURSECOURSE).

  7. Define attributes: Double-click the first attribute to set the Primary Key (e.g., CRS_CODECRS\_CODE).

  8. Insert additional attributes by hovering over the entity border until a red line appears (e.g., CRS_TITLECRS\_TITLE, CRS_DESCRIPTIONCRS\_DESCRIPTION).

  9. Connect entities using the Relationship object.

  10. Set the Relationship Format: Right-click the line, set width to 1.5 pt1.5\,pt, and arrow sizes to Jumbo.

  11. Attach the "11" side and the "MM" side to the participating entities.

  12. Set Foreign Keys: Right-click an attribute in the "many" side entity and select Set Foreign Key.

  13. Adjust Cardinality: Use the context menu to set Begin/End Symbols (e.g., "Zero or more").

Converting EER Diagrams to MySQL

Using an Artist database example (Painter paints Paintings; Paintings displayed in Gallery):

  • Painter Table SQL:sql CREATE TABLE PAINTER ( PTR_NUM CHAR(4) NOT NULL UNIQUE, PTR_LASTNAME CHAR(15) NOT NULL, PTR_FIRSTNAME CHAR(15) NOT NULL, PTR_AREACODE CHAR(3), PTR_PHONE CHAR(8), PRIMARY KEY (PTR_NUM) );     

  • Gallery Table SQL:sql CREATE TABLE GALLERY ( GAL_NUM CHAR(4) NOT NULL UNIQUE, GAL_OWNER CHAR(35), GAL_AREACODE CHAR(3) NOT NULL, GAL_PHONE CHAR(8) NOT NULL, GAL_RATE NUMBER(4,2), PRIMARY KEY (GAL_NUM) );     

  • Painting Table SQL (with Foreign Keys):sql CREATE TABLE PAINTING ( PTNG_NUM CHAR(4) NOT NULL UNIQUE, PTNG_TITLE CHAR(35), PTNG_PRICE NUMBER(9,2), PTR_NUM CHAR(4) NOT NULL, GAL_NUM CHAR(4), PRIMARY KEY (PTNG_NUM), FOREIGN KEY (PTR_NUM) REFERENCES PAINTER ON UPDATE CASCADE, FOREIGN KEY (GAL_NUM) REFERENCES GALLERY ON UPDATE CASCADE );     

Operations of Database Management Systems

Storage File Structures

Physical storage is categorized into three levels:

  1. Primary Storage: Fastest but volatile (Cache, Main Memory).

  2. Secondary Storage: Non-volatile, moderately fast access, also called online storage (Flash memory, Magnetic Disks).

  3. Tertiary Storage: Non-volatile, slow access, used for archiving (Magnetic tape, Optical storage).

Database Construction (Microsoft Access)
  1. Start MS Access.

  2. Select Blank desktop database.

  3. Rename the file (e.g., SaleCoSaleCo) and choose a storage folder.

  4. Click Create.

Security Techniques
  1. Define User/Security Groups and Roles: Assign privileges as a unit. For example, an "Advisor" role might have restricted read access to specific views.

  2. Assign Security Controls: Administrators assign specific rights (e.g., SELECTSELECT, UPDATEUPDATE) for individual database objects and can revoke them during maintenance or data breaches.

Transaction Management and the ACID Test

A transaction is any logical unit of work (reading or writing). Transactions must satisfy four properties:

  • Atomicity: All operations in a transaction must be completed; otherwise, the entire transaction is aborted.

  • Consistency: The database must move from one consistent state to another.

  • Isolation: Data used by one transaction cannot be accessed by another until the first is finished.

  • Durability: Committed changes are permanent and cannot be lost, even during system failure.

SQL Transaction Example
INSERT INTO INVOICE VALUES (1009, 10016, '18-Jan-2016', 256.99, 20.56, 277.55, 'cred', 0.00, 277.55);
UPDATE PRODUCT SET PROD_QOH = PROD_QOH - 1 WHERE PROD_CODE = '89-WRE-Q';
COMMIT;
Querying in MS Access
  1. Click CREATE then Query Design.

  2. Use the Show Table dialog to add data sources.

  3. Drag fields from the table box to the QBE Grid.

  4. Set Sort options (Ascending/Descending).

  5. Toggle to Datasheet View to see results.

  6. Save the query using a naming convention (e.g., qryPhoneListqryPhoneList).

Performance and Maintenance of Database Management Systems

MySQL Installation and Configuration
  1. Run the MySQL Installer; choose Developer Default.

  2. Execute requirements (e.g., Microsoft Visual C++).

  3. Configure TCP/IP and X Protocol ports.

  4. Select Authentication: Use SHA-256 based passwords.

  5. Set the root user password.

  6. Define the service name and start the server.

  7. Validate via MySQL Workbench.

Operating System Level Optimization
  • Swappiness: Linux parameter controlling data transfer between RAM and disk. Recommended value for MySQL is 11. Set via # echo 1 > /proc/sys/vm/swappiness.

  • I/O Scheduler: Determines read/write commitment algorithms. For databases, the deadline or noop scheduler is preferred over the default cfq. Set via # echo "noop" > /sys/block/xvda/queue/scheduler.

  • Filesystems: XFS and ext4 are standard. Use the noatimenoatime mount option to reduce overhead.

  • Memory Allocation (jemalloc): A memory allocator focused on fragmentation avoidance. Installed via aptinstalllibjemalloc−devapt install libjemalloc-dev and enabled by overriding the MySQL service configuration.

  • CPU Governor: Use the performance setting to maintain maximum clock speed for best throughput.

System Monitoring Metrics
  • CPU: Monitor frequency and cache memory usage using Resource Monitor.

  • Disk: Monitor available space to prevent crashes; databases require headroom for spikes.

  • Memory (RAM): Use Task Manager to ensure the database operates in memory as much as possible.

  • Network: Use netstatnetstat to check for errors and Resource Monitor for throughput.

  • MySQL Server Status: Use SHOWSTATUSSHOW STATUS to view counters and gauges. Monitor Availability (uptime), Client Connections (should be minimized), and Query Counts.

Load Balancers

Load balancers provide high availability and transparency:

  • ProxySQL: Understands MySQL traffic; can split reads from writes.

  • HAProxy: A TCP/HTTP load balancer. Distribution is configured in three sections: globalglobal, defaultsdefaults, listenlisten.

  • MySQL Router: Distributes traffic within an InnoDB cluster and hides cluster topology from applications.

MySQL in the Cloud

Companies can use Database-as-a-Service (DBaaS) options for scalability and automatic backups:

  • Amazon RDS: Users configure product, version, instance size (e.g., instance classes), and storage (IOPS). Private network configuration is recommended.

  • Google Cloud SQL: Offers a more straightforward setup for MySQL and PostgreSQL.

  • Azure SQL: Offers "Single Server" or "Flexible Server" options for managed MySQL services.

Questions & Discussion

Self-Assessment 1: Fundamentals
  • Discuss databases and DBMS: A database stores data; a DBMS is the software suite that manages that data and controls access.

  • What are database applications? Banking, social media, POS, and school management.

  • Explain the purpose of database systems: Efficient management, concurrent access, and security for large data volumes.

  • What are database actors? Administrators, designers, analysts, and end-users.

Self-Assessment 2: Concepts and Architecture
  • Schema vs. Instance: A schema is a logical blueprint; an instance is a data-filled snapshot at a point in time.

  • Database Languages: DDL (define), DML (manipulate), DCL (control), and TCL (transactions).

  • Database Architectures: 11, 22, and 33-tier designs separating client, application, and data layers.

Self-Assessment 3: Modeling and Design
  • Describe the design process: Involves three stages: conceptual, logical, and physical design within the DBLC.

  • How to perform normalization: Eliminate repeating groups, identify primary keys, and map dependencies.

  • How to build an ERD: Narrative creation, business rule identification, entity/attribute identification, and diagramming in tools like Visio.

Self-Assessment 4: Operations
  • Storage Media types: Primary (RAM), Secondary (Flash/Disk), Tertiary (Tape/Optical).

  • ACID Test components: Atomicity, Consistency, Isolation, and Durability.

  • Performing Queries: Using QBE (Query by Example) in MS Access to select fields and sort data.

Self-Assessment 5: Performance and Maintenance
  • System Monitoring components: CPU, Disk space, Memory, Network throughput, and Server status variables.

  • Cloud Platform choices: Amazon RDS (high customization), Google Cloud SQL (simplicity), and Azure SQL (flexible server options).