SQL
SQL
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).
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.
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.
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:
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
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