0% found this document useful (0 votes)
2 views5 pages

SQL Introduction Class9 (1)

SQL, or Structured Query Language, is the standard language used to communicate with databases, allowing users to manage and manipulate data effectively. It includes various commands grouped into categories such as Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), Transaction Control Language (TCL), and Programmatic SQL. Learning SQL is essential for students interested in technology and data management, as it is widely used across industries.

Uploaded by

sanya792006
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)
2 views5 pages

SQL Introduction Class9 (1)

SQL, or Structured Query Language, is the standard language used to communicate with databases, allowing users to manage and manipulate data effectively. It includes various commands grouped into categories such as Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), Transaction Control Language (TCL), and Programmatic SQL. Learning SQL is essential for students interested in technology and data management, as it is widely used across industries.

Uploaded by

sanya792006
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

SQL — Structured Query Language

An Introduction for Class 9 Students


Based on: Groff, J. R. & Weinberg, P. N., SQL: The Complete Reference, Osborne/McGraw-Hill, 1999.

1. What is SQL?
SQL stands for Structured Query Language (pronounced either as "sequel" or as the three letters S-Q-L).
It is the standard computer language used to communicate with databases — systems that store and
organise large amounts of information.
Think of a database like a very large filing cabinet, and SQL as the set of instructions you give to the
cabinet to find, add, change, or remove files. Whether it is a school storing student records, a bank
keeping track of accounts, or an online shop managing orders — SQL is the language behind the scenes.
SQL was originally developed by IBM in the 1970s and has since become an international standard
adopted by organisations such as the American National Standards Institute (ANSI) and the International
Standards Organization (ISO). Today, almost every major software company — including Microsoft,
Oracle, and Google — uses SQL in their products.

Key Features of SQL


- It works with relational databases — databases that store information in tables made up of rows
and columns, much like a spreadsheet.
- It is vendor-independent — the same SQL knowledge can be applied across different database
systems such as MySQL, Oracle, and Microsoft SQL Server.
- It uses simple, English-like sentences, making it easier to read and learn compared to most
programming languages.
- It can be used interactively (typing commands directly) or embedded inside other programming
languages like Python or Java.
- It is a complete database language — it can create tables, add data, update records, delete entries,
and control who has access to what.

2. How Does SQL Work?


SQL works by sending requests to a Database Management System (DBMS). The DBMS is the software
that actually stores and manages the data. When you write an SQL statement, you are giving an
instruction to the DBMS, which then carries it out and returns a result.
For example, if a shopkeeper wants to see all customers who placed orders in the last month, they would
write an SQL statement asking the DBMS for that information. The DBMS searches through the database
and returns the matching records.
A database is made up of tables. Each table stores information about one type of thing — for example, a
Customers table, an Orders table, and a Products table. Rows in a table represent individual records (one
row per customer), and columns represent the details (name, address, phone number, etc.).

A Simple Example
Here is what a basic SQL instruction looks like. This statement asks the database to show the name and
city of all customers:
SELECT NAME, CITY
FROM CUSTOMERS

The word SELECT tells the database what information to fetch, and FROM tells it which table to look in.
As you can see, SQL reads almost like plain English.

3. Types of SQL Commands


SQL has about 40 different commands (also called statements), and they are grouped into five main
categories based on what they do. These are: Data Definition Language (DDL), Data Manipulation
Language (DML), Data Control Language (DCL), Transaction Control Language (TCL), and
Programmatic SQL. Each category is explained below.

3.1 Data Definition Language (DDL)


DDL commands are used to define and manage the structure of a database. They create, change, or
remove the containers (tables, views, etc.) that hold data. They do not deal with the data inside — only
the structure.

Command What It Does Example Use


CREATE TABLE Creates a new table in the database. Create a Students table with
columns for name, age, and roll
number.
DROP TABLE Permanently removes a table and all its data. Remove the old Results table that is
no longer needed.
ALTER TABLE Changes the structure of an existing table — Add a new column called Email to
add, remove, or rename columns. the Students table.
CREATE VIEW Creates a virtual table based on a query, useful Create a view showing only students
for simplifying complex data. who passed.
DROP VIEW Removes a view from the database. Delete the PassedStudents view.
CREATE INDEX Builds an index on a column to make searches Index the Roll_Number column for
faster. quicker lookup.

Example — creating a simple table:


CREATE TABLE Students (
Roll_Number INT,
Name VARCHAR(50),
Age INT
)

3.2 Data Manipulation Language (DML)


DML commands are used to work with the data inside the tables — adding new records, reading existing
ones, updating values, or deleting rows. These are the commands used most frequently in everyday
database work.

Command What It Does Example Use


SELECT Retrieves data from one or more tables. The Show all students whose age is
most commonly used SQL command. above 15.
INSERT Adds new rows of data into a table. Add a new student record to the
Students table.
UPDATE Changes existing data in a table. Correct a student's name that was
spelled wrongly.
DELETE Removes rows from a table. Remove the record of a student who
has left the school.

Examples of DML in use:


-- Adding a new student
INSERT INTO Students (Roll_Number, Name, Age)
VALUES (101, 'Priya Sharma', 15)

-- Reading data
SELECT Name, Age FROM Students WHERE Age > 14

-- Updating a record
UPDATE Students SET Age = 16 WHERE Roll_Number = 101

-- Deleting a record
DELETE FROM Students WHERE Roll_Number = 101

3.3 Data Control Language (DCL)


DCL commands control who is allowed to access the database and what they are allowed to do. In a
school, for example, a teacher might be allowed to view student marks but not change them, while the
principal can do both. DCL manages these permissions.

Command What It Does Example Use


GRANT Gives a user permission to perform certain Allow a teacher to view the Students
actions on a table. table.
REVOKE Takes away permissions that were previously Remove a teacher's access to the
granted. Marks table after they leave.

Example:
GRANT SELECT ON Students TO Teacher_Ravi
REVOKE SELECT ON Students FROM Teacher_Ravi

3.4 Transaction Control Language (TCL)


A transaction is a group of SQL operations that are treated as one single unit of work. Either all of them
succeed together, or none of them go through. This is important in situations where multiple steps must
all happen correctly — for example, transferring money from one bank account to another involves both
debiting one account and crediting another. If one step fails, the other must also be reversed.

Command What It Does Example Use


COMMIT Saves all changes made during the current Confirm a money transfer once both
transaction permanently. steps succeed.
ROLLBACK Cancels all changes made during the current Undo a failed bank transfer so no
transaction if something goes wrong. money is lost.
SET TRANSACTION Defines rules for how the current transaction Set the transaction as read-only to
should behave. prevent any changes.

Example of how COMMIT and ROLLBACK protect data:


-- Transfer money from Account A to Account B
UPDATE Accounts SET Balance = Balance - 500 WHERE Account = 'A'
UPDATE Accounts SET Balance = Balance + 500 WHERE Account = 'B'
COMMIT -- Only save if both steps above worked
-- If something went wrong, type: ROLLBACK

3.5 Programmatic SQL


These are specialised commands used when SQL is written inside other computer programmes — for
example, inside a Python or Java application that talks to a database. They allow a programme to run
queries step by step, process one row at a time, and handle complex situations.

Command What It Does Example Use


DECLARE Declares a cursor — a pointer that moves Loop through all student records one
through query results one row at a time. by one.
OPEN Opens a declared cursor and runs the query. Start reading through the list of
students.
FETCH Retrieves the next row from an open cursor. Get the next student's details from
the list.
CLOSE Closes the cursor when finished. Stop reading once all students have
been processed.
PREPARE / EXECUTE Prepares an SQL statement in advance and Run the same query many times
runs it later, useful for speed and security. with different values.

4. Summary — All Five Categories at a Glance


Category Main Commands Purpose
DDL — Data Definition CREATE, DROP, ALTER Define and change the structure of tables and
other database objects.
DML — Data SELECT, INSERT, UPDATE, Add, read, update, and remove data inside
Manipulation DELETE tables.
DCL — Data Control GRANT, REVOKE Control user permissions and access to
database objects.
TCL — Transaction COMMIT, ROLLBACK, SET Manage groups of operations to ensure data is
Control TRANSACTION never half-saved.
Programmatic SQL DECLARE, OPEN, FETCH, Used inside programs to process query results
CLOSE, PREPARE, EXECUTE row by row.

5. Why is SQL Important to Learn?


SQL is one of the most in-demand skills in the world of technology and business today. Almost every
company that stores data — which is nearly every company — relies on SQL to manage it. From a
hospital keeping patient records to a railway system managing ticket bookings, SQL is working behind
the scenes.
For students interested in computers, data science, business, or engineering, learning SQL early gives a
strong head start. It is also a practical skill — even a basic understanding of SQL can help you understand
how apps and websites store and retrieve information.
Most importantly, SQL is designed to be readable. Unlike complex coding languages, an SQL statement
tells you almost exactly what it is doing in plain words — making it one of the friendliest places to start
learning about databases.

Source: Groff, J. R. & Weinberg, P. N. SQL: The Complete Reference. Osborne/McGraw-Hill, 1999. ISBN: 0072118458.

You might also like