unit-4 sql
unit-4 sql
Introduction to SQL
A database is a structured collection of data that can be stored electronically. It can include numbers,
words, images, videos, and files.
A Database Management System (DBMS) is a software system that allows users to create, define,
manipulate and manage databases. It provides a way for organizations to store, organize and retrieve large
amounts of data quickly and efficiently in an organized manner.
Types of DBMS
There are several types of Database Management Systems (DBMS), each tailored to different data
structures, scalability requirements, and application needs. The most common types are as follows:
1. Relational Database Management System (RDBMS)
RDBMS organizes data into tables (relations) composed of rows and columns. It uses primary keys to
uniquely identify rows and foreign keys to establish relationships between tables. Queries are written
in SQL (Structured Query Language), which allows for efficient data manipulation and retrieval.
Examples: MySQL, Oracle, Microsoft SQL Server and Postgre SQL.
2. NoSQL DBMS
NoSQL systems are designed to handle large-scale data and provide high performance for scenarios
where relational models might be restrictive. They store data in various non-relational formats, such
as key-value pairs, documents, graphs, or columns. These flexible data models enable rapid scaling
and are well-suited for unstructured or semi-structured data.
Examples: MongoDB, Cassandra, DynamoDB and Redis.
3. Object-Oriented DBMS (OODBMS)
OODBMS integrates object-oriented programming concepts into the database environment, allowing
data to be stored as objects. This approach supports complex data types and relationships, making it ideal
for applications requiring advanced data modeling and real-world simulations.
Examples: ObjectDB, db4o.
What is SQL?
SQL stands for Structured Query Language. It is a standardized programming language used
to manage and manipulate relational databases. It enables users to perform a variety of tasks such as
querying data, creating and modifying database structures, and managing access permissions. SQL is
widely used across various relational database management systems such as MySQL, PostgreSQL,
Oracle, and SQL Server.
• when data needs to be retrieved from a database, SQL is used to construct and send the request.
The Database Management System (DBMS) processes the SQL query, retrieves the requested
data, and returns it to the user or application. Instead of specifying step-by-step procedures, SQL
statements describe what data should be retrieved, organized, or modified, allowing the DBMS to
handle how the operations are executed efficiently.
• SQL (Structured Query Language) is a language to operate databases; it includes Database
Creation, Database Deletion, Fetching Data Rows, Modifying & Deleting Data rows, etc.
• SQL stands for Structured Query Language which is a computer language for storing,
manipulating and retrieving data stored in a relational database. SQL was developed in the 1970s
by IBM Computer Scientists and became a standard of the American National Standards Institute
(ANSI) in 1986, and the International Organization for Standardization (ISO) in 1987.
• SQL is the standard language to communicate with Relational Database Systems. All the
Relational Database Management Systems (RDMS) like MySQL, MS Access, Oracle, Sybase,
Informix, Postgres and SQL Server use SQL as their Standard Database Language.
Why SQL?
• Allows users to define the data in a database and manipulate that data.
• Allows to embed within other languages using SQL modules, libraries & pre-compilers.
• Allows users to create and drop databases and tables.
• 1970 − Dr. Edgar F. "Ted" Codd of IBM is known as the father of relational databases. He
described a relational model for databases.
• 1986 − IBM developed the first prototype of relational database and standardized by ANSI. The
first relational database was released by Relational Software which later came to be known as
Oracle.
• 1987 − SQL became the part of the International Organization for Standardization (ISO).
• User-Friendly and Accessible: SQL is designed for a broad range of users, including those with
minimal programming experience, making it approachable for non-technical individuals.
• Declarative Language: As a non-procedural language, SQL allows users to specify what data is
needed rather than how to retrieve it, focusing on the desired results rather than the retrieval
process.
• Efficient Database Management: SQL enables the creation, modification, and management of
databases efficiently, saving time and simplifying complex database operations.
• Standardized Language: Based on ANSI (American National Standards Institute) and ISO
(International Organization for Standardization) standards, SQL ensures consistency and stability
across various database management systems (DBMS).
• Command Structure: SQL does not require a continuation character for multi-line queries,
allowing flexibility in writing commands across one or multiple lines.
• Execution Mechanism: Queries are executed using a termination character (e.g., a semicolon ;),
enabling immediate and accurate command processing.
• Built-in Functionality: SQL includes a rich set of built-in functions for data manipulation,
aggregation, and formatting, empowering users to handle diverse data-processing needs
effectively.
There are various components included in this process. These components are −
• Query Dispatcher
• Optimization Engines
A classic query engine handles all the non-SQL queries, but a SQL query engine won't
handle logical files. Following is a simple diagram showing the SQL Architecture −
1. Input: The process begins when a user submits an SQL query through a database interface or
application. This query typically specifies the desired operation, such as data retrieval, insertion,
updating, or deletion.
2. Parsing: The query is passed to the query processor, which breaks it into smaller units called
tokens. These tokens represent keywords, table names, column names, and other elements of the
query. The processor then validates the syntax against SQL standards and the database schema to
ensure the query is well-formed and executable.
3. Optimization: After parsing, the query is handed to the optimizer, which evaluates multiple ways
to execute the query. The optimizer considers factors like indexes, table statistics, and available
resources to generate the most efficient execution plan. This step ensures that the query runs with
minimal resource consumption and maximum performance.
4. Execution: The execution engine follows the plan provided by the optimizer. It interacts with the
storage engine, which retrieves, manipulates, or updates the required data from the database
tables. During this step, SQL statements like SELECT, INSERT, UPDATE, or DELETE are
translated into actions performed on the underlying data.
5. Output: Once the execution engine processes the query, the result is formatted and returned to the
user. Depending on the query type, the output could be a result set (for SELECT queries) or an
acknowledgment of the operation (for INSERT, UPDATE, or DELETE queries).
Features Of SQL
1. Flexibility and Scalability
SQL offers users flexibility and scalability for relational database management systems. With SQL, it
is easier to create new tables while dropping or deleting previously-created or scantily used tables.
Programmers use SQL to program applications to access a database, making it a comprehensive and
effective application development tool. SQL is suitable for every large or small organization, no
matter the size.
It has rich transactional support. Structured Query Language’s programming capability of handling
large records while also managing several other transactions is top-notch.
4. High Performance
Another feature of SQL is that it offers a high-performance programming capability for high usage,
incredibly transactional, and heavy workload database systems. Structured Query Language’s
programming provides different ways to describe data more analytically.
5. High Availability
SQL is compatible with other databases such as Microsoft SQL Server, Oracle Database, MS Access,
MySQL, SAP Adaptive Server, and more.
These RDBMSs support SQL, and it is easier to create application extensions for procedural
programming and several other SQL functions that are extra features, hence making SQL a strong
tool.
6. High Security
SQL also has high security as one of its notable features. It’s easy to give permissions on views,
procedures, and tables. So with SQL, you get optimum security for your data.
7. SQL’s Management Ease
Almost every Relational Database Management System uses Structured Query Language. Some of the
common and standard SQL commands include “Delete,” “Insert,” “Select,” “Update,” and “Drop.”
These commands help users manage large amounts of data from a database efficiently and quickly.
8. Open Source
Structured Query Language has the feature of being an open-source programming language great for
building relational database management systems (RDBMS). This makes it a great pick for
developers and programmers who are looking for a community of professionals to learn from off, and
it’s also one of the benefits of SQL.
It is a portable language
SQL is easily accessible and can be used on servers, personal computers, laptops, and some mobile
phones. In addition, its portability feature makes it a preferred choice among users.
Advantages of SQL
• Quicker Query Processing: SQL Server has the advantage of offering faster and quicker query
processing. You can efficiently and quickly retrieve a large amount of data. What’s more,
operations like manipulation, deletion, or insertion of data are carried out in little to no time at all
making it one of the strong advantages of SQL.
• Standardized Language: SQL offers a uniform platform globally to its numerous users because
of documentation and long establishment through the years, making it a standardized language for
analysts and developers.
• No Coding Skills Required: When carrying out data retrieval, numerous lines of code aren’t
needed. The syntactical rules aren’t so complex in SQL either, making it a user-friendly language.
In SQL, you use basic keywords like “Update,” “Select,” “Into,” and “Insert.”
• Interactive: The SQL server is interactive, and the language is easy to understand and learn. Users
can receive the answers to very complex queries in seconds.
• Portable: Portability is one of the benefits of SQL Server. You can use SQL in programs in
laptops, servers, or personal computers independent of any existing platform or operating system.
Besides, you can embed SQL with other apps as you require or need.
• Multiple or Different Data Views: The SQL language helps users to make different views of a
database structure while also making databases for different users.
Disadvantages of SQL
Despite the many advantages of SQL or the great SQL features and benefits, there are still some
disadvantages of using SQL. Below are some disadvantages of SQL:
• Difficult Interface: SQL’s interface is a little complex and difficult. This alone makes it difficult
for new users to deal with the database at first.
• Partial Control: The presence of hidden business rules means that the database isn’t given
complete control.
• Cost: The fact that some versions of SQL are costly makes accessibility difficult for some
programmers.