Download as PPTX, PDF, TXT or read online from Scribd
Download as pptx, pdf, or txt
You are on page 1of 21
DBMS
Databases Management System
What is Database ?
A database is an organized collection of dat
that is stored and accessed electronically. It allows users to store, retrieve, manage and manipulate data efficiently
Data / Information Types of Databases:
Relational Databases (RDBMS): Store data in tables and use
SQL for data manipulation (e.g., MySQL, PostgreSQL). NoSQL Databases: Non-relational databases that store data in various formats (key-value, document, column-family, graph) and are used for handling large-scale data and high- velocity applications (e.g., MongoDB, Cassandra, Redis).
In-Memory Databases: Store data in the system's main
memory (RAM) for faster access (e.g., Redis).
Distributed Databases: Spread across multiple locations or
nodes and used for scaling and high availability (e.g., Cassandra, Amazon DynamoDB). SQL Structures Query Language developed at IBM by Donald D. Chamberlin and Raymond F. Boyce for their database software “System R” in 1970 Oracle made it popular. By 1986, ANSI and ISO officially adopted the SQL and standard Language for RDBMS.
IMS Larry Ellison
ANSI = American National Standards Institute
ISO = International Organization for Standardization
SQL WHAT IS QUERY LANGUAGE ?
A Query Language is a type of programming language designed
specifically for querying and retrieving data from a database or information system. It allows users to request specific data by specifying criteria or conditions, and the system returns the data that matches those criteria. KEY FEATURES OF QUERY LANGUAGES : Data Retrieval: The primary function of a query language is to fetch data from databases. Users can retrieve data by specifying what they need, such as all records where a certain condition is met. Data Manipulation: Query languages often include commands for modifying data, such as inserting new records, updating existing records, or deleting records. Data Definition: Some query languages also allow users to define or modify the structure of the database, such as creating or altering tables and their relationships. Data Control: Query languages may include commands for managing access to data, including granting or revoking permissions for users or roles. HOW SQL WORKS
SQL (Structured Query Language) is a powerful tool used
to interact with relational databases. It allows users to perform a variety of tasks, including data retrieval, insertion, updating, deletion, and managing the structure of databases. 1. SQL STATEMENT WRITING The first step is to write an SQL statement. SQL statements are written in a specific syntax and can be classified into different types based on their purpose: Data Query Language (DQL): For data retrieval (e.g., SELECT). Data Definition Language (DDL): For defining and modifying database structures (e.g., CREATE, ALTER, DROP). Data Manipulation Language (DML): For modifying data (e.g., INSERT, UPDATE, DELETE). Data Control Language (DCL): For controlling access to data (e.g., GRANT, REVOKE). 2. PARSING THE SQL STATEMENT When an SQL statement is submitted to the database management system (DBMS), the first step is parsing. During parsing: • The SQL statement is checked for syntax errors. • The DBMS analyzes the structure of the statement to understand what the user is asking for. If there are errors, such as a misspelled keyword or incorrect syntax, an error message is returned. 3. OPTIMIZATION Once the SQL statement is parsed and validated, the DBMS's query optimizer takes over. The optimizer's job is to determine the most efficient way to execute the query. This might involve:
Choosing the best indexes: If the table has indexes on certain
columns, the optimizer may decide to use them to speed up data retrieval. Deciding the join order: If multiple tables are involved, the optimizer determines the best order to join them. Selecting the access paths: The optimizer decides how to access the required data, whether by scanning the table, using indexes, or using other methods. The optimization process is crucial for ensuring that queries run as quickly and efficiently as possible. 4. QUERY EXECUTION After optimization, the DBMS executes the query. During this phase:
• The DBMS retrieves or modifies the data as specified in the SQL
statement. • For a SELECT statement, the data is fetched from the tables, possibly filtered or sorted according to the query conditions. • For INSERT, UPDATE, or DELETE statements, the DBMS modifies the data in the database. The execution involves various operations like scanning tables, applying filters (e.g., WHERE clauses), joining tables, aggregating data (e.g., using GROUP BY), and more. 5. RESULT RETURN Once the query is executed: • For a SELECT query, the result set (the data that matches the query criteria) is returned to the user. This could be in the form of rows of data displayed in a table format. • For INSERT, UPDATE, or DELETE queries, the DBMS returns a success message, often indicating how many rows were affected. 6. ERROR HANDLING If the query encounters any issues during execution, such as trying to access a non-existent table, violating constraints (e.g., primary key constraints), or data type mismatches, the DBMS will return an error message. 7. TRANSACTION MANAGEMENT SQL supports transactions, which are sequences of operations that are treated as a single unit of work. Transactions follow the ACID properties (Atomicity, Consistency, Isolation, Durability): Atomicity: Ensures that all operations within a transaction are completed successfully. If any operation fails, the transaction is rolled back. Consistency: Ensures that the database remains in a consistent state before and after the transaction. Isolation: Ensures that the operations within a transaction are isolated from other transactions until they are completed. Durability: Ensures that once a transaction is committed, the changes are permanent, even in the case of a system failure.