0% found this document useful (0 votes)
4 views

SQL

The document discusses the importance of data, databases, and Database Management Systems (DBMS) in organizing and managing information. It explains various types of databases, the role of SQL in data manipulation, and the significance of constraints and joins in maintaining data integrity. The conclusion emphasizes the necessity of effective data management systems in today's data-driven world.

Uploaded by

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

SQL

The document discusses the importance of data, databases, and Database Management Systems (DBMS) in organizing and managing information. It explains various types of databases, the role of SQL in data manipulation, and the significance of constraints and joins in maintaining data integrity. The conclusion emphasizes the necessity of effective data management systems in today's data-driven world.

Uploaded by

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

THEORY

DATA
Data is raw information collected from various sources. It can take many forms, such as
numbers, text, images, audio, or video. Data is often categorized into types like structured
(organized in tables or databases), unstructured (like social media posts or videos), and semi-
structured (like JSON or XML files). Whether it’s a temperature reading, a customer’s shopping
history, or responses from a survey, data provides the foundation for analysis and decision-
making.
In today’s world, data plays a crucial role in almost every field, from business and science to
education and entertainment. When analyzed properly, data helps uncover patterns, trends, and
insights that can guide actions or predict outcomes. For example, businesses use customer data to
improve marketing strategies, while researchers use data to support scientific findings. Without
data, much of the technology and decisions we rely on every day would not be possible.

DATABASE
A database is an organized collection of data that is stored and accessed electronically. It allows
users to efficiently store, retrieve, manage, and update information. Databases are commonly
used in various applications—like websites, mobile apps, banking systems, and more—where
large amounts of data need to be handled securely and accurately. Data in a database is typically
structured in tables (rows and columns), especially in relational databases.
There are different types of databases based on how they store and organize data. Relational
databases (like MySQL, PostgreSQL, or Oracle) use tables and are ideal for structured data.
NoSQL databases (like MongoDB or Firebase) are used for more flexible data formats and can
handle unstructured or semi-structured data better. Databases are managed by software called
Database Management Systems (DBMS), which help users interact with the data through
queries, often written in SQL (Structured Query Language).

DATABASE MANAGEMENT SYSTEM


A Database Management System (DBMS) is a software system that enables users to define,
create, maintain, and control access to databases. It acts as a bridge between the raw data stored
in a database and the applications or users that interact with it. By providing a systematic and
organized way to store and manage data, a DBMS simplifies complex tasks such as data entry,
updates, retrieval, and deletion. It helps ensure that the data remains consistent, secure, and
easily accessible to authorized users.
One of the primary benefits of a DBMS is data integrity. It ensures that the data entered into the
database is accurate and consistent across all users and applications. For example, if multiple
users try to update the same record at the same time, the DBMS uses concurrency control to
manage these transactions and prevent conflicts or duplication. It also supports data abstraction,
which means users can view data in a simple format without needing to understand the complex
underlying structure.
Another major function of a DBMS is data security. It allows administrators to set user
permissions, ensuring that only authorized individuals can access or modify certain parts of the
data. This is especially important for organizations that handle sensitive information, such as
personal customer details, financial records, or confidential business documents. Most DBMS
systems also include backup and recovery features, which automatically save data at regular
intervals and restore it in case of hardware failure or data corruption.
Query processing is another essential aspect of DBMS. Users can write queries—most
commonly in Structured Query Language (SQL)—to perform operations like searching for
specific records, sorting data, updating values, or generating reports. A well-optimized DBMS
handles these queries efficiently, even when dealing with large volumes of data. This makes it a
powerful tool for data analysis, business intelligence, and decision-making.
There are several types of DBMS systems based on how they organize data. The most common
is the Relational DBMS (RDBMS), such as MySQL, Oracle, PostgreSQL, and Microsoft SQL
Server, which store data in tables with rows and columns. These systems use relationships
between tables to reduce redundancy and maintain integrity. On the other hand, NoSQL DBMS
like MongoDB, Cassandra, and Firebase are designed for more flexible and unstructured data,
such as JSON documents, making them suitable for big data and real-time web applications.
STRUCTURED QUERY LANGUAGE

SQL (Structured Query Language) is a programming language used for managing and
manipulating relational databases. It allows users to perform essential tasks like storing,
updating, deleting, retrieving, and managing data. SQL is widely known for being simple,
readable, and powerful, making it the global standard for interacting with relational database
systems.Whether you're creating a school database, running an e-commerce platform, or
analyzing millions of customer records, SQL helps organize and access data efficiently.

SQL is designed to be easy to read and write, even for beginners. For example:
 SELECT * FROM students; retrieves all records from the "students" table.
 INSERT INTO students (name, age) VALUES ('Sita', 20); adds a new record.
 UPDATE students SET age = 21 WHERE name = 'Sita'; changes existing data.
 DELETE FROM students WHERE name = 'Sita'; removes a record.

Types of SQL-based Databases


Although SQL is a standard language, different database systems have their own
implementations of it, with slight variations and additional features. These are often referred to
as SQL-based database management systems (DBMS).

1. MySQL
 Open-source and widely used.
 Popular for web development (used with PHP, WordPress, etc.).
 Owned by Oracle Corporation.
2. PostgreSQL
 Open-source and highly advanced.
 Known for reliability and support for complex queries.
 Frequently used in analytics and data-heavy applications.
3. Oracle Database
 Commercial DBMS known for performance, security, and scalability.
 Used in enterprise-level applications and banking systems.
4. Microsoft SQL Server
 Developed by Microsoft.
 Integrated well with Windows and .NET applications.
 Offers tools like SSMS (SQL Server Management Studio) for ease of use.
5. SQLite
 Lightweight and self-contained.
 Doesn’t require a server; often used in mobile apps and browsers.
 Great for local storage and smaller-scale projects.
6. MariaDB
 A fork of MySQL, created after concerns about Oracle’s acquisition.
 Fully compatible with MySQL but with additional features and improvements.

Uses of SQL
SQL is used in almost every industry because data is everywhere — in businesses, schools,
hospitals, social media, and more. Here are some of the primary uses:
1. Data Retrieval
 Fetch specific information from large databases using commands like SELECT.
 Example: “Show all customers from Kathmandu who bought a product last month.”
2. Data Insertion & Updates
 Add new records (INSERT) or change existing ones (UPDATE) easily.
 Useful for keeping data up to date without replacing the whole database.
3. Data Analysis & Reporting
 Combine data from multiple tables using JOIN, filter with WHERE, group data with
GROUP BY, and sort with ORDER BY.
 Used in analytics dashboards and business intelligence systems.
4. Database Creation & Management
 Create or delete tables and structures using CREATE or DROP.
 Modify columns, data types, and rules using ALTER.
5. Access Control & Security
 Grant and restrict access using GRANT and REVOKE commands.
 Ensures that only authorized users can view or change sensitive data.
6. Transactions & Reliability
 SQL supports transactions (COMMIT, ROLLBACK) to ensure data integrity during
critical operations (e.g., in banking systems).
7. Automation & Integration
 SQL is used in combination with programming languages like Python, Java, PHP, and
web technologies for building dynamic applications.

Key Terms Used in SQL


Database:
A database is a collection of organized data that can be accessed, managed, and updated. It stores
data in tables and is used to store and retrieve information. In SQL, databases are created using
the CREATE DATABASE command.
Table:
A table is a collection of rows and columns in a database. Each table contains data about a
specific entity, such as customers, orders, or products. Tables are the fundamental building
blocks in a relational database, and data is stored in them in a structured manner.
Column:
A column is a vertical set of values in a table. Each column represents a specific attribute of the
data being stored, such as a name, date, or price. Columns are defined with a name and a data
type (e.g., VARCHAR, INT, DATE).
Row:
A row is a horizontal set of values in a table, representing a single record or entity. Each row
corresponds to one entry in the table, with values for each column. For example, a row in a
"students" table might represent a single student, with values for their ID, name, and age.
Query:
A query is a request for data or information from a database. SQL queries are written using the
SELECT statement to retrieve data from one or more tables. Queries can include conditions
(using WHERE), sorting (ORDER BY), grouping (GROUP BY), and aggregation (e.g., SUM(),
AVG()).
Select:
The SELECT statement is used to retrieve data from one or more tables in a database. It is one of
the most commonly used SQL commands. The SELECT statement allows users to specify which
columns to retrieve and apply filters, sorting, and grouping to the result set.
Insert:
The INSERT statement is used to add new records into a table. It allows users to specify values
for each column in the table, creating a new row of data.
Update:
The UPDATE statement is used to modify existing records in a table. It allows users to change
the values in one or more columns for specific rows that meet certain conditions.
Delete:
The DELETE statement is used to remove records from a table. It can delete one or more rows
based on a specified condition.
Where:
The WHERE clause is used to filter records in a query based on specified conditions. It helps
narrow down the result set by specifying criteria that must be met for a row to be included in the
result.
Join:
A JOIN is used to combine rows from two or more tables based on a related column. Common
types of joins include INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN. Joins are used
to retrieve data from multiple tables in a single query.
Index:
An index is a database object that improves the speed of data retrieval operations on a table. It
works like an index in a book, allowing the database to quickly locate the rows that match a
query condition.
Constraint:
A constraint is a rule applied to columns in a table to ensure data integrity. Common types of
constraints include NOT NULL (ensures a column cannot have a NULL value), UNIQUE
(ensures all values in a column are unique), and FOREIGN KEY (ensures referential integrity
between tables).
Primary Key:
A primary key is a column or set of columns in a table that uniquely identifies each row. It must
contain unique values and cannot contain NULL values. Every table can have only one primary
key.
Foreign Key:
A foreign key is a column or set of columns in one table that links to the primary key in another
table. It establishes a relationship between the two tables and ensures referential integrity.
Aggregate Functions:
Aggregate functions are used to perform calculations on a set of values and return a single result.
Common aggregate functions include COUNT(), SUM(), AVG(), MIN(), and MAX(). These are
often used with the GROUP BY clause to summarize data.
Group By:
The GROUP BY clause is used to group rows that have the same values into summary rows. It is
often used with aggregate functions to calculate values for each group.
Order By:
The ORDER BY clause is used to sort the result set of a query. It can sort data in ascending
(ASC) or descending (DESC) order based on one or more columns.
Transaction:
A transaction is a sequence of SQL statements that are executed as a single unit. Transactions
ensure data consistency and integrity, allowing operations to be rolled back if an error occurs.
Common transaction commands include BEGIN, COMMIT, and ROLLBACK.
View:
A view is a virtual table that is based on the result of a query. It is used to simplify complex
queries and provide a consistent interface to the data. Views do not store data themselves but
instead display data from underlying tables.
LAB WORK

DATA DEFINITION LANGUAGE (DDL)


Data Definition Language (DDL) is a subset of SQL (Structured Query Language) that is used to
define, modify, and manage the structure of database objects such as: tables, schemas, views, and
indexes
It focuses not on the data itself, but on how the data is stored and organized in the database.

CREATE
Create command is used to create new database objects like tables, views, or databases.
It is used to make new database structures for storing data.
Example:
ALTER
Alter command is used to modify the structure of an existing database object.
It is used to add, delete, or change columns in a table.

Example:

DROP
Drop command is used to delete database objects permanently.
It is used to remove a table or database completely from the system.

Example:

TRUNCATE
Truncate command is used to delete all records from a table quickly.
It is used to remove data while keeping the table structure intact.

Example :
DATA MANIPULATION LANGUAGE (DML)
Data Manipulation Language (DML) is a subset of SQL that deals with managing and
manipulating the data inside database tables.
If DDL is about creating the structure, then DML is about working with the actual data —
adding, updating, retrieving, or deleting records.

INSERT
Insert command is used to add new data into a table.
It is used when you want to store a new record.

Example :

SELECT
Select command is used to retrieve data from a table.
It is used when you want to view the records stored in the database.

Example :

DELETE
Delete command is used to remove data from a table.
It is used when you want to delete specific records.

Example :
Transaction Control Language ( TCL)
Transaction Control Language (TCL) is a set of SQL commands used to manage transactions in a
database.Transactions are a group of SQL operations that are executed together — either all
succeed, or none do.TCL ensures data integrity and helps control how and when changes made
by DML commands (like INSERT, UPDATE, DELETE) are permanently saved or undone.

COMMIT Command
Commit command is used to permanently save all changes made in the transaction.
Example :

ROLLBACK Command
Rollback command is used to undo all changes made since the last commit.

Example:

DATA CONTROL LANGUAGE (DCL)


Data Control Language (DCL) is a subset of SQL used to control access to data in a database.
It deals with permissions and security, helping database administrators manage who can do what
with the data.

GRANT Command
Grant command is used to give permissions to users to perform specific actions.

REVOKE Command
Revoke command is used to take back permissions previously granted to a user.
CONSTRAINTS
Constraints in SQL are rules that are applied to columns in a table to enforce data integrity and
ensure the accuracy and reliability of the data in the database. These constraints restrict the type
of data that can be inserted into a table, helping prevent invalid data from being stored.

Primary Key
Uniquely identifies each record in a table.

Not Null
Ensures that a column cannot have a NULL value.

Unique
Ensures that all the values in a column are different.

Foreign key
Creates a relationship between two tables.
Check
Ensures that all values in a column meet a specific condition.

VIEW
A View in SQL is a virtual table that is based on the result of a SQL query. It doesn’t store data
physically like a table — instead, it shows data dynamically from one or more tables whenever
you access it.

Creating a view

Select from view

Drop the view


JOINS
Joins in SQL are used to combine rows from two or more tables based on a related column
between them — usually a primary key in one table and a foreign key in another. Joins allow you
to pull data together that is stored separately in a relational database.

Making table for join

Inner join
Only matching records from both tables.

Left join
Returns all rows from the left table and matching rows from the right table.
Outer join
Returns all rows from the right table, and matching rows from the left

Self join
Joins a table to itself.
CONCLUSION
In today’s information-driven world, data is at the heart of nearly every digital process. From
businesses making strategic decisions to scientists analyzing experiments, raw data is the
foundation upon which modern innovation stands. However, raw data on its own is not
particularly useful unless it is properly organized, managed, and interpreted — which is where
databases, Database Management Systems (DBMS), and SQL come into play.
A database provides a structured way to store vast amounts of information in a manner that
allows for efficient retrieval, manipulation, and analysis. Whether in a traditional relational
format or in more modern NoSQL structures, databases are essential to storing and maintaining
the integrity of digital information. As the volume and complexity of data continue to grow, so
does the importance of effective data management systems.
DBMS software serves as a crucial intermediary between the raw data and the users or
applications that interact with it. By offering tools for query processing, data abstraction,
security, concurrency control, and backup management, a DBMS ensures that the database
remains consistent, secure, and scalable. Whether in large enterprises handling millions of
transactions per day or in small applications tracking user inputs, DBMS solutions have become
integral to digital infrastructure.
SQL (Structured Query Language) further empowers users by providing a standardized,
powerful, and readable way to interact with relational databases. From creating tables and
defining data structures with Data Definition Language (DDL) to manipulating data using Data
Manipulation Language (DML), SQL bridges the gap between human logic and machine-level
data storage. Commands like SELECT, INSERT, UPDATE, and DELETE make it possible to
work with the data in intuitive ways, while advanced features like joins, indexes, constraints,
transactions, and views make SQL capable of handling complex data requirements.
Through practical lab exercises and command-based operations, we gain a clear understanding
of how theory is applied in real-world scenarios. Creating tables, altering structures, inserting
and retrieving records, and managing databases not only help build technical skills but also
cultivate an appreciation for how organized data systems support everything from e-commerce
platforms and mobile apps to financial institutions and healthcare systems.
REFERENCES

IBM. (n.d.). What is a database?. IBM. https://www.ibm.com/topics/database


TutorialsPoint. (n.d.). SQL Overview. https://www.tutorialspoint.com/sql/sql-overview.htm
W3Schools. (n.d.). SQL DDL. https://www.w3schools.com/sql/sql_ref_ddl.asp
GeeksforGeeks. (2023, February 5). SQL | DDL, DQL, DML, DCL and TCL Commands.
https://www.geeksforgeeks.org/sql-ddl-dql-dml-dcl-tcl-commands/
Oracle. (n.d.). Oracle Database. https://www.oracle.com/database/
W3Schools. (n.d.). SQL DML. https://www.w3schools.com/sql/sql_ref_dml.asp
W3Schools. (n.d.). SQL DDL. https://www.w3schools.com/sql/sql_ref_ddl.asp
SQLite. (n.d.). About SQLite. https://www.sqlite.org/about.html

You might also like