Educational Galaxy shield logo

Educational Galaxy

LEARN • THINK • SPEAK • GROW

Chapter 8: Introduction to Structured Query Language (SQL)

Original notes — ready CBSE (NCERT, English Medium) • Class 11 • Computer Science • Book: Informatics Practices

Print lets you save as PDF from the browser. This is not a textbook PDF.

Chapter 8: Introduction to Structured Query Language (SQL) — EG's own notes, in simple words

Book: Informatics Practices (CBSE, Class 11)  |  Chapter 8  |  Medium: English

Labelled diagram for Chapter 8: Introduction to Structured Query Language (SQL)

Diagram (labels on the image): Diagram (labels on the image): a SELECT query — choose columns, filter rows, and receive a sorted result.

Illustration for Chapter 8: Introduction to Structured Query Language (SQL)

Ask precisely: SELECT, FROM and WHERE together fetch exactly the rows you need.

1. 1. What SQL is

SQL (Structured Query Language) is the standard language for working with relational databases. With SQL you create tables, insert rows, read data, change it, and delete it. SQL commands fall into groups: DDL (data definition, e.g. CREATE TABLE), DML (data manipulation, e.g. INSERT, UPDATE, DELETE) and DQL (data query, e.g. SELECT).

SQL is not case-sensitive for its keywords, but table and column names follow the database's rules. This chapter uses MySQL-style SQL, the common school choice.

2. 2. Creating tables and inserting data

Original example: CREATE TABLE Students (RollNo INT PRIMARY KEY, Name VARCHAR(30), Class CHAR(3), Marks INT); creates a table with four fields, RollNo as primary key. VARCHAR(30) means text up to 30 characters; INT means whole numbers.

Rows are added with INSERT: INSERT INTO Students VALUES (12, “Asha”, “XI”, 88); inserts one student's record. Columns can be listed to insert only some fields, leaving the rest to defaults.

3. 3. Reading data with SELECT

SELECT picks columns, FROM picks the table, and WHERE filters rows: SELECT Name, Marks FROM Students WHERE Marks >= 90; lists only high scorers' names and marks. SELECT * means all columns. ORDER BY sorts results (ASC rising, DESC falling), and DISTINCT removes duplicate values.

Aggregate functions summarise: COUNT(*) counts rows, SUM(Marks) totals, AVG(Marks) averages, MAX() and MIN() find extremes. GROUP BY groups rows (e.g. by class) so aggregates can be computed per group.

4. 4. Changing and deleting data

UPDATE changes existing rows: UPDATE Students SET Marks = 90 WHERE RollNo = 12; changes only Asha's marks — the WHERE clause is essential, because without it every row would change. DELETE removes rows: DELETE FROM Students WHERE RollNo = 12; removes one student. DROP TABLE removes the whole table, structure and data together — the most dangerous command in the chapter.

At a glance — chart / table

CommandGroupOriginal example
CREATE TABLEDDLCREATE TABLE Students (...);
INSERTDMLINSERT INTO Students VALUES (12, “Asha”, “XI”, 88);
SELECT ... WHEREDQLSELECT Name FROM Students WHERE Marks >= 90;
UPDATEDMLUPDATE Students SET Marks = 90 WHERE RollNo = 12;
DELETEDMLDELETE FROM Students WHERE RollNo = 12;
DROP TABLEDDLDROP TABLE Students;

Key Terms / Important Terms

  • SQL — Structured Query Language for relational databases.
  • DDL — Data Definition Language: CREATE, ALTER, DROP.
  • DML — Data Manipulation Language: INSERT, UPDATE, DELETE.
  • DQL — Data Query Language: SELECT.
  • Primary key — A field uniquely identifying each row.
  • WHERE clause — A condition filtering which rows a command affects.
  • Aggregate function — A function summarising many rows, e.g. SUM, AVG, COUNT.

Remember

  • SELECT columns FROM table WHERE condition — in that order.
  • UPDATE and DELETE without WHERE affect EVERY row — always include WHERE.
  • DDL = structure (CREATE/DROP); DML = rows (INSERT/UPDATE/DELETE); DQL = queries (SELECT).
  • COUNT/SUM/AVG/MAX/MIN summarise; GROUP BY summarises per group.

Exam Tip / Common Mistake

Common mistake: running UPDATE or DELETE without WHERE in an exam answer. Always write the WHERE clause — examiners specifically test whether you know the danger of omitting it.

Practice set — try it yourself

  1. Write SQL to create a Books table with BookID as primary key, Title and Price. Hint: Hint: CREATE TABLE with field names, types, and PRIMARY KEY.
  2. Write SQL to insert one book of your choice into Books. Hint: Hint: INSERT INTO Books VALUES (...); matching the column order.
  3. Write SQL to list titles of books priced above 500. Hint: Hint: SELECT Title FROM Books WHERE Price > 500;
  4. What happens if UPDATE Books SET Price = 100; runs without WHERE? Hint: Hint: The condition is missing, so every row is affected.
  5. Write SQL to find the average price of books. Hint: Hint: AVG() summarises a column.

Questions with Answers

  1. Write SQL to create a Students table with RollNo (primary key), Name, Class and Marks. Answer: Answer: CREATE TABLE Students (RollNo INT PRIMARY KEY, Name VARCHAR(30), Class CHAR(3), Marks INT);
  2. Write SQL to insert a student of your choice into Students. Answer: Answer: INSERT INTO Students VALUES (12, “Asha”, “XI”, 88);
  3. Write SQL to list the names and marks of students scoring 90 or above, highest first. Answer: Answer: SELECT Name, Marks FROM Students WHERE Marks >= 90 ORDER BY Marks DESC;
  4. Why must UPDATE and DELETE carry a WHERE clause? Answer: Answer: Because without WHERE the command affects every row in the table. UPDATE without WHERE would change all rows' values, and DELETE without WHERE would empty the whole table.
  5. Distinguish DDL, DML and DQL with one command each. Answer: Answer: DDL defines structure, e.g. CREATE TABLE. DML manipulates rows, e.g. INSERT. DQL queries data, e.g. SELECT.