Curriculum
Course: Grade XII Computer Science
Login
Text lesson

Ch-8 Structured Query Language (SQL)

School Revise · Class 11 Computer Science · Chapter 8

Structured Query Language (SQL)

Code 083, Class 12. SQL is the language for talking to a database. Here we create tables and ask questions of the data with queries.

DDL

defines tables

DML

works with data

What this chapter is about

SQL (Structured Query Language) creates and uses databases. DDL commands define tables (CREATE), and DML commands work with the data (INSERT, SELECT, UPDATE, DELETE).

1. Selecting data

SELECT reads data. SELECT * FROM STUDENT shows all columns, and a WHERE clause filters rows. ORDER BY sorts the result.

SELECT name FROM STUDENT WHERE marks > 80; (shows the names of students who scored above 80)

2. Aggregate functions

These summarise data: COUNT counts rows, SUM adds, AVG averages, and MAX and MIN find the largest and smallest.

3. Changing data

INSERT INTO adds a row, UPDATE changes values, and DELETE removes rows. Always use a WHERE clause with UPDATE and DELETE so you change only the rows you mean to.

Practise with the interactive

Explore the idea by tapping. The interactive opens right here in the lesson.

Coding practice problems, with answers

Type each one into the code lab above, then open the card to see the worked solution and its output.

Problem 1. Show all rows of the STUDENT table.

SOLUTION

SELECT * FROM STUDENT;

OUTPUT

all rows and columns of STUDENT
Problem 2. Show only the names.

SOLUTION

SELECT name FROM STUDENT;

OUTPUT

the name column for every student
Problem 3. Show students who scored above 80.

SOLUTION

SELECT name FROM STUDENT WHERE marks > 80;

OUTPUT

names of students with marks above 80
Problem 4. Sort students by marks, highest first.

SOLUTION

SELECT * FROM STUDENT ORDER BY marks DESC;

OUTPUT

rows sorted by marks, largest first
Problem 5. Count the number of students.

SOLUTION

SELECT COUNT(*) FROM STUDENT;

OUTPUT

the number of rows
Problem 6. Find the average marks.

SOLUTION

SELECT AVG(marks) FROM STUDENT;

OUTPUT

the average of the marks column
Problem 7. Find the highest marks.

SOLUTION

SELECT MAX(marks) FROM STUDENT;

OUTPUT

the largest value in marks
Problem 8. Add a new student.

SOLUTION

INSERT INTO STUDENT VALUES (4, “Sana”, 91);

OUTPUT

one new row is added
Problem 9. Change a student marks.

SOLUTION

UPDATE STUDENT SET marks = 95 WHERE rollno = 1;

OUTPUT

marks of roll number 1 becomes 95
Problem 10. List the different cities.

SOLUTION

SELECT DISTINCT city FROM STUDENT;

OUTPUT

each city listed once

Practice set A, multiple choice

1. Which command reads data?

SELECT.

2. Which clause filters rows?

WHERE.

3. Which function counts rows?

COUNT.

4. Which command adds a new row?

INSERT INTO.

Quick summary

SQL creates and uses databases. DDL defines tables (CREATE); DML works with data. SELECT reads data, WHERE filters rows, ORDER BY sorts. Aggregate functions COUNT, SUM, AVG, MAX and MIN summarise data. INSERT adds rows, UPDATE changes them, and DELETE removes them, and UPDATE and DELETE should use a WHERE clause.

Open the Virtual Lab

These free Class 12 Computer Science notes explain SQL, SELECT with WHERE and ORDER BY, aggregate functions COUNT SUM AVG MAX and MIN, and INSERT UPDATE and DELETE with worked examples and practice, for CBSE students across India and the Gulf including the UAE, Saudi Arabia, Qatar, Oman, Kuwait and Bahrain.

© 2026 School Revise. All rights reserved. Original content aligned to the CBSE and NCERT Class 12 Computer Science syllabus. Unauthorised copying is not permitted.

Layer 1
Login Categories