CBSE Class 12 · Computer Science, code 083 · Unit 3, 20 marks

Class 12 computer science SQL questions, with the output of every query.

Reading SQL is easy. Predicting what a query returns when a fee is NULL, or when two tables share one column too many, is where marks are lost. These 50 class 12 computer science SQL questions follow the 083 syllabus from keys to natural join, on two small tables you can hold in your head. Write your answer, then open ours and see exactly what MySQL gave back.

Live one to one · 50 original questions · every result from a real server · any day, your hour

Start here

Courses that teach this SQL

The questions below test SQL. These courses teach it: alone, as part of the whole 083 syllabus, or after the Python it connects to.

Ans. The short version

Class 12 computer science SQL questions in CBSE 083 cover keys and constraints, DDL and DML commands, SELECT with WHERE, LIKE, BETWEEN, IN and NULL, aggregate functions, GROUP BY with HAVING, and three joins: cartesian product, equi-join and natural join. Database Management is 20 of the 70 theory marks in 2026-27, and the lab test adds 4 marks for SQL queries. This page has 50 original questions on two tables, with real MySQL output. Modern Age Coders teaches SQL live, personalised one to one at your timing, and a priority demo gives you a full class to try first.

Start here. Two tables, 20 marks

Which SQL questions come in Class 12 Computer Science?

In the CBSE sample paper for 2026-27, the database unit fills six 1-mark questions, one 2-mark question and three 4-mark questions. One of those three is Python with MySQL; the rest is the SQL and relational theory on this page.

Where the 20 marks sit

Sample paper questionWhat it wantsMarks
4, 9, 13, 15, 19, 21Keys, domain, degree and cardinality, one query or command to choose, NULL6
27Two commands, or a difference with examples2
32One table: four queries to write, or four outputs4
34Two tables: four queries, joins among them4
35A Python-MySQL program4

In 32 and 34 the marking scheme gives one mark for each correct query or output. There is no partial credit printed, so a missing condition can cost the full mark.

The database: an animal shelter

PET holds the animals. VISIT holds each trip to a vet. One pet may have several visits or none. Two weights were never taken, and one fee was never charged: those NULLs are there on purpose.

Keep both tables open beside you. Every query from Question 8 on was run on MySQL 26, and an older version in your lab may word an error slightly differently.

PET

PIDPNameSpeciesAgeMWeightArrived
P01BiscuitDog1411.52026-08-03
P02MishtiCat83.22026-08-19
P03RocketDog3018.42026-09-02
P04KajuRabbit61.82026-09-02
P05SimbaCat26NULL2026-10-11
P06BhaluDog9NULL2026-10-20
P07PihuCat52.42026-11-05
P08MomoRabbit112.12026-11-05

AgeM is the age in months.

VISIT

VNoPIDVetReasonFeeVDate
101P01Dr SenVaccine4002026-08-10
102P03Dr RoyInjury15002026-09-03
103P02Dr SenVaccine4002026-09-12
104P05Dr RoyCheckup3002026-10-12
105P01Dr SenCheckup3002026-10-30
106P03Dr RoyInjury9002026-11-06
107P07Dr IyerVaccineNULL2026-11-09

Relational model, Questions 1 to 5

  1. Q1. What are the degree and the cardinality of PET?
    Answer Degree 6 (attributes) and cardinality 8 (tuples).
  2. Q2. Is PName a candidate key of PET?
    Answer No. No name repeats today, but a second Biscuit may arrive tomorrow. A candidate key must be unique for every row the table could ever hold, so PID is the only one here, and it is the primary key.
  3. Q3. Which attribute is a foreign key, and what does it refer to?
    Answer VISIT.PID refers to PET.PID. It repeats in VISIT because a pet may visit more than once.
  4. Q4. What is the domain of Species in this shelter?
    Answer The set of values it may take: {Dog, Cat, Rabbit}.
  5. Q5. One pet is adopted and its row deleted, then a column Colour is added. State the new degree and cardinality.
    Answer Degree 7, cardinality 7. Rows change the cardinality, columns change the degree.

Notes first, then commands

Class 12 SQL notes: every command in the syllabus on one screen

DDL commands build and change the table. DML commands work on the rows inside it. Anything not in this list, such as subqueries, views, triggers or outer joins, is outside the 083 syllabus for 2026-27.

Command or clauseKindWhat it doesShape to remember
CREATE DATABASE, USE, DROP DATABASEDDL (USE only selects)Make, open, remove a databaseCREATE DATABASE shelter;
SHOW DATABASES, SHOW TABLES, DESCRIBELook onlyList databases, list tables, show columnsDESCRIBE PET;
CREATE TABLEDDLColumns, types, constraintsPName VARCHAR(15) NOT NULL
ALTER TABLEDDLAdd or remove a column or the primary keyALTER TABLE PET ADD Tag CHAR(6);
DROP TABLEDDLRemove rows and structureDROP TABLE PET;
INSERTDMLAdd rowsINSERT INTO PET VALUES (...);
UPDATEDMLChange values in existing rowsUPDATE PET SET ... WHERE ...;
DELETEDMLRemove rows, keep the tableDELETE FROM PET WHERE ...;
SELECT, DISTINCT, aliasDMLChoose columns, drop repeated rows, rename a headingSELECT AgeM / 12 AS Years
WHERE with IN, BETWEEN, LIKE, IS NULLClauseKeep some rowsLIKE '_i%'
GROUP BY, HAVINGClausesMake groups, keep some groupsHAVING COUNT(*) > 2
ORDER BYClauseSort the resultORDER BY Species, AgeM DESC
MAX, MIN, SUM, AVG, COUNTAggregateOne value from many rowsAVG(Fee)

Data types: CHAR(n) has a fixed length, VARCHAR(n) holds up to n characters, then INT, FLOAT and DATE written as '2026-11-05'. Constraints: NOT NULL, UNIQUE, PRIMARY KEY.

Building and changing tables, Questions 6 to 13

  1. Q6. Write the commands to create a database named shelter and open it.
    Answer
    SQLanswer
    CREATE DATABASE shelter;
    USE shelter;
  2. Q7. Write the command to create PET. PID is the primary key and the name must not be empty.
    Answer
    SQLanswer
    CREATE TABLE PET(
        PID     CHAR(3) PRIMARY KEY,
        PName   VARCHAR(15) NOT NULL,
        Species VARCHAR(10),
        AgeM    INT,
        Weight  FLOAT,
        Arrived DATE);
  3. Q8. Show the structure of VISIT.
    Answer
    MySQLquery and result
    DESCRIBE VISIT;
    +--------+-------------+------+-----+---------+-------+
    | Field  | Type        | Null | Key | Default | Extra |
    +--------+-------------+------+-----+---------+-------+
    | VNo    | int         | NO   | PRI | NULL    |       |
    | PID    | char(3)     | NO   |     | NULL    |       |
    | Vet    | varchar(15) | YES  |     | NULL    |       |
    | Reason | varchar(10) | YES  |     | NULL    |       |
    | Fee    | int         | YES  |     | NULL    |       |
    | VDate  | date        | YES  |     | NULL    |       |
    +--------+-------------+------+-----+---------+-------+

    VNo says NO under Null although NOT NULL was never typed for it: a primary key brings that rule along.

  4. Q9. Add a column Tag to PET, change its type, then remove it.
    Answer
    MySQLquery and result
    ALTER TABLE PET ADD Tag CHAR(6);
    Query OK, 0 rows affected
    Records: 0  Duplicates: 0  Warnings: 0
    
    ALTER TABLE PET MODIFY Tag VARCHAR(10);
    Query OK, 8 rows affected
    Records: 8  Duplicates: 0  Warnings: 0
    
    ALTER TABLE PET DROP COLUMN Tag;
    Query OK, 0 rows affected
    Records: 0  Duplicates: 0  Warnings: 0
  1. Q10. Remove the primary key of VISIT and then put it back.
    Answer
    MySQLquery and result
    ALTER TABLE VISIT DROP PRIMARY KEY;
    Query OK, 7 rows affected
    Records: 7  Duplicates: 0  Warnings: 0
    
    ALTER TABLE VISIT ADD PRIMARY KEY (VNo);
    Query OK, 0 rows affected
    Records: 0  Duplicates: 0  Warnings: 0

    Dropping takes no column name, since a table has only one primary key. Adding needs it in brackets.

  2. Q11. What happens when a row repeats a primary key, and when it leaves a NOT NULL column empty?
    Answer
    MySQLquery and result
    INSERT INTO PET VALUES
    ('P03', 'Tara', 'Dog', 7, 6.5, '2026-11-12');
    ERROR 1062 (23000): Duplicate entry 'P03' for key 'pet.PRIMARY'
    
    INSERT INTO PET VALUES
    ('P09', NULL, 'Dog', 7, 6.5, '2026-11-12');
    ERROR 1048 (23000): Column 'PName' cannot be null

    Neither row is stored.

  3. Q12. Tara's age and weight are not known yet. Insert what is known, then complete it.
    Answer
    MySQLquery and result
    INSERT INTO PET (PID, PName, Species)
    VALUES ('P09', 'Tara', 'Dog');
    Query OK, 1 row affected
    
    UPDATE PET SET AgeM = 7, Arrived = '2026-11-12'
    WHERE PID = 'P09';
    Query OK, 1 row affected
    Rows matched: 1  Changed: 1  Warnings: 0
    
    SELECT * FROM PET WHERE PID = 'P09';
    +-----+-------+---------+------+--------+------------+
    | PID | PName | Species | AgeM | Weight | Arrived    |
    +-----+-------+---------+------+--------+------------+
    | P09 | Tara  | Dog     |    7 |   NULL | 2026-11-12 |
    +-----+-------+---------+------+--------+------------+

    Columns left out of the list become NULL. Weight still is.

  4. Q13. Delete Tara's row. What does MySQL say if the PID does not exist?
    Answer
    MySQLquery and result
    DELETE FROM PET WHERE PID = 'P09';
    Query OK, 1 row affected
    
    DELETE FROM PET WHERE PID = 'P55';
    Query OK, 0 rows affected

    No error, only 0 rows affected. And without WHERE, every row goes.

One table, rows and columns

SQL queries for Class 12 Computer Science: SELECT and WHERE, Questions 14 to 23

WHERE keeps a row only when its condition is true for that row. False drops it, and so does unknown, which is what NULL produces.

  1. Q14. Show each dog's name and its age in years under the heading Years.
    Answer
    MySQLquery and result
    SELECT PName, AgeM / 12 AS Years FROM PET
    WHERE Species = 'Dog';
    +---------+--------+
    | PName   | Years  |
    +---------+--------+
    | Biscuit | 1.1667 |
    | Rocket  | 2.5000 |
    | Bhalu   | 0.7500 |
    +---------+--------+

    Division with / gives decimals even for two integers.

  2. Q15. List the species in the shelter, each once.
    Answer
    MySQLquery and result
    SELECT DISTINCT Species FROM PET;
    +---------+
    | Species |
    +---------+
    | Dog     |
    | Cat     |
    | Rabbit  |
    +---------+

    DISTINCT works on the whole row you select. With two columns, it removes repeated pairs.

  3. Q16. Names and ages of pets aged 8 to 14 months.
    Answer
    MySQLquery and result
    SELECT PName, AgeM FROM PET
    WHERE AgeM BETWEEN 8 AND 14;
    +---------+------+
    | PName   | AgeM |
    +---------+------+
    | Biscuit |   14 |
    | Mishti  |    8 |
    | Bhalu   |    9 |
    | Momo    |   11 |
    +---------+------+

    Mishti at 8 and Biscuit at 14 are both in: BETWEEN includes its ends.

  4. Q17. Cats and rabbits younger than 10 months.
    Answer
    MySQLquery and result
    SELECT PName, Species FROM PET
    WHERE Species IN ('Cat', 'Rabbit') AND AgeM < 10;
    +--------+---------+
    | PName  | Species |
    +--------+---------+
    | Mishti | Cat     |
    | Kaju   | Rabbit  |
    | Pihu   | Cat     |
    +--------+---------+
  5. Q18. Names with i as the second letter, and names of exactly four letters.
    Answer
    MySQLquery and result
    SELECT PName FROM PET WHERE PName LIKE '_i%';
    +---------+
    | PName   |
    +---------+
    | Biscuit |
    | Mishti  |
    | Simba   |
    | Pihu    |
    +---------+
    
    SELECT PName FROM PET WHERE PName LIKE '____';
    +-------+
    | PName |
    +-------+
    | Kaju  |
    | Pihu  |
    | Momo  |
    +-------+

    One underscore is one character. Four underscores and no % means exactly four.

  1. Q19. Which pets have not been weighed? Why does = NULL not find them?
    Answer
    MySQLquery and result
    SELECT PName, Weight FROM PET WHERE Weight IS NULL;
    +-------+--------+
    | PName | Weight |
    +-------+--------+
    | Simba |   NULL |
    | Bhalu |   NULL |
    +-------+--------+
    
    SELECT PName, Weight FROM PET WHERE Weight = NULL;
    Empty set

    A comparison with an unknown value is unknown, never true.

  2. Q20. Predict: pets for which Weight is NOT less than 5.
    Answer
    MySQLquery and result
    SELECT PName, Weight FROM PET WHERE NOT Weight < 5;
    +---------+--------+
    | PName   | Weight |
    +---------+--------+
    | Biscuit |   11.5 |
    | Rocket  |   18.4 |
    +---------+--------+

    Simba and Bhalu are missing. NOT unknown is still unknown.

  3. Q21. Sort by species, and the oldest first inside each species.
    Answer
    MySQLquery and result
    SELECT PName, Species, AgeM FROM PET
    ORDER BY Species, AgeM DESC;
    +---------+---------+------+
    | PName   | Species | AgeM |
    +---------+---------+------+
    | Simba   | Cat     |   26 |
    | Mishti  | Cat     |    8 |
    | Pihu    | Cat     |    5 |
    | Rocket  | Dog     |   30 |
    | Biscuit | Dog     |   14 |
    | Bhalu   | Dog     |    9 |
    | Momo    | Rabbit  |   11 |
    | Kaju    | Rabbit  |    6 |
    +---------+---------+------+

    DESC belongs only to the column beside it. Species is still ascending.

  4. Q22. Find dogs and cats older than 20 months. What goes wrong without brackets?
    Answer
    MySQLquery and result
    SELECT PName, Species, AgeM FROM PET
    WHERE Species = 'Dog' OR Species = 'Cat' AND AgeM > 20;
    +---------+---------+------+
    | PName   | Species | AgeM |
    +---------+---------+------+
    | Biscuit | Dog     |   14 |
    | Rocket  | Dog     |   30 |
    | Simba   | Cat     |   26 |
    | Bhalu   | Dog     |    9 |
    +---------+---------+------+
    
    SELECT PName, Species, AgeM FROM PET
    WHERE (Species = 'Dog' OR Species = 'Cat') AND AgeM > 20;
    +--------+---------+------+
    | PName  | Species | AgeM |
    +--------+---------+------+
    | Rocket | Dog     |   30 |
    | Simba  | Cat     |   26 |
    +--------+---------+------+

    AND is done before OR, so the first query takes every dog. The second is correct; IN would also do.

  5. Q23. Mishti weighs 3.2. Why does SELECT PName FROM PET WHERE Weight = 3.2; return nothing, when the same query with 11.5 finds Biscuit?
    Answer
    MySQLquery and result
    SELECT PName FROM PET WHERE Weight = 3.2;
    Empty set
    
    SELECT PName FROM PET WHERE Weight = 11.5;
    +---------+
    | PName   |
    +---------+
    | Biscuit |
    +---------+

    FLOAT stores an approximation of 3.2. The value 11.5 can be stored exactly. Use a range for FLOAT columns.

Many rows, one answer

GROUP BY and HAVING in Class 12 SQL, Questions 24 to 30

GROUP BY makes one row for each group, and HAVING keeps or drops whole groups. WHERE has already done its work on single rows before any group exists.

The order MySQL thinks in

StepClauseQuestion it answers
1FROMWhich table, or which pair of tables?
2WHEREWhich rows stay?
3GROUP BYWhich rows belong together?
4HAVINGWhich groups stay?
5SELECTWhat is shown for each?
6ORDER BYIn what order?

You write SELECT first and MySQL reaches it fifth. That is why WHERE cannot use COUNT(*): at step 2 nothing has been counted.

  1. Q24. Predict all six values: SELECT COUNT(*), COUNT(Weight), MIN(AgeM), MAX(AgeM), SUM(AgeM), AVG(AgeM) FROM PET;
    Answer
    MySQLquery and result
    SELECT COUNT(*), COUNT(Weight), MIN(AgeM),
    MAX(AgeM), SUM(AgeM), AVG(AgeM) FROM PET;
    +----------+---------------+-----------+-----------+-----------+-----------+
    | COUNT(*) | COUNT(Weight) | MIN(AgeM) | MAX(AgeM) | SUM(AgeM) | AVG(AgeM) |
    +----------+---------------+-----------+-----------+-----------+-----------+
    |        8 |             6 |         5 |        30 |       109 |   13.6250 |
    +----------+---------------+-----------+-----------+-----------+-----------+

    COUNT(Weight) skips the two NULLs. 109 over 8 is 13.6250.

  2. Q25. Find the number of visits, the number of paid visits, the total and the average fee.
    Answer
    MySQLquery and result
    SELECT COUNT(*), COUNT(Fee), SUM(Fee), AVG(Fee)
    FROM VISIT;
    +----------+------------+----------+----------+
    | COUNT(*) | COUNT(Fee) | SUM(Fee) | AVG(Fee) |
    +----------+------------+----------+----------+
    |        7 |          6 |     3800 | 633.3333 |
    +----------+------------+----------+----------+

    AVG divides by 6, not by 7. A NULL fee is left out; a fee of 0 would have been counted.

  3. Q26. How many pets of each species, and how old is the oldest of each?
    Answer
    MySQLquery and result
    SELECT Species, COUNT(*) AS Pets, MAX(AgeM) AS Oldest
    FROM PET GROUP BY Species;
    +---------+------+--------+
    | Species | Pets | Oldest |
    +---------+------+--------+
    | Dog     |    3 |     30 |
    | Cat     |    3 |     26 |
    | Rabbit  |    2 |     11 |
    +---------+------+--------+
  1. Q27. Predict the output, with care for Dr Iyer: SELECT Vet, COUNT(*), SUM(Fee) FROM VISIT GROUP BY Vet;
    Answer
    MySQLquery and result
    SELECT Vet, COUNT(*), SUM(Fee) FROM VISIT GROUP BY Vet;
    +---------+----------+----------+
    | Vet     | COUNT(*) | SUM(Fee) |
    +---------+----------+----------+
    | Dr Sen  |        3 |     1100 |
    | Dr Roy  |        3 |     2700 |
    | Dr Iyer |        1 |     NULL |
    +---------+----------+----------+

    The only fee in that group is NULL, so the sum is NULL, not 0.

  2. Q28. Which reasons occur more than twice?
    Answer
    MySQLquery and result
    SELECT Reason, COUNT(*) FROM VISIT
    GROUP BY Reason HAVING COUNT(*) > 2;
    +---------+----------+
    | Reason  | COUNT(*) |
    +---------+----------+
    | Vaccine |        3 |
    +---------+----------+
  3. Q29. Leave out injuries. Show vets whose remaining fees total more than 500, the highest first.
    Answer
    MySQLquery and result
    SELECT Vet, SUM(Fee) AS Total FROM VISIT
    WHERE Reason <> 'Injury' GROUP BY Vet;
    +---------+-------+
    | Vet     | Total |
    +---------+-------+
    | Dr Sen  |  1100 |
    | Dr Roy  |   300 |
    | Dr Iyer |  NULL |
    +---------+-------+
    
    SELECT Vet, SUM(Fee) AS Total FROM VISIT
    WHERE Reason <> 'Injury'
    GROUP BY Vet HAVING SUM(Fee) > 500
    ORDER BY Total DESC;
    +--------+-------+
    | Vet    | Total |
    +--------+-------+
    | Dr Sen |  1100 |
    +--------+-------+

    The first result is what HAVING sees. Dr Roy had 2700 in Question 27, but only 300 once injuries were removed.

  4. Q30. Both of these fail. Say why. (I) SELECT Vet FROM VISIT WHERE COUNT(*) > 1 GROUP BY Vet; (II) SELECT PName, Species, COUNT(*) FROM PET GROUP BY Species;
    Answer
    MySQLquery and result
    SELECT Vet FROM VISIT WHERE COUNT(*) > 1 GROUP BY Vet;
    ERROR 1111 (HY000): Invalid use of group function
    
    SELECT PName, Species, COUNT(*) FROM PET
    GROUP BY Species;
    ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'shelter.PET.PName' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

    (I) has an aggregate in WHERE; move it to HAVING. In (II), three dogs share one row, so which name should it show? A server with a looser setting may print one of them, and that is worse, since it looks like an answer.

Two tables

Joins in Class 12 Computer Science: cartesian product, equi-join, natural join, Questions 31 to 38

A cartesian product pairs every row of one table with every row of the other. An equi-join keeps the pairs whose common column is equal. A natural join does that by itself, on every column name the tables share.

Cartesian productEqui-joinNatural join
Conditionnoneyou write it: PET.PID = VISIT.PIDautomatic, on all shared names
Rows for our tables8 x 7 = 5677
Columns with SELECT *6 + 6 = 1212, PID twice11, PID once
Pets with no visitappear, wrongly paireddo not appeardo not appear
  1. Q31. How many rows are in the cartesian product of PET and VISIT?
    Answer
    MySQLquery and result
    SELECT COUNT(*) FROM PET, VISIT;
    +----------+
    | COUNT(*) |
    +----------+
    |       56 |
    +----------+
  2. Q32. Show each visit with the pet's name, the vet, the reason and the fee.
    Answer
    MySQLquery and result
    SELECT PName, Vet, Reason, Fee FROM PET, VISIT
    WHERE PET.PID = VISIT.PID;
    +---------+---------+---------+------+
    | PName   | Vet     | Reason  | Fee  |
    +---------+---------+---------+------+
    | Biscuit | Dr Sen  | Vaccine |  400 |
    | Rocket  | Dr Roy  | Injury  | 1500 |
    | Mishti  | Dr Sen  | Vaccine |  400 |
    | Simba   | Dr Roy  | Checkup |  300 |
    | Biscuit | Dr Sen  | Checkup |  300 |
    | Rocket  | Dr Roy  | Injury  |  900 |
    | Pihu    | Dr Iyer | Vaccine | NULL |
    +---------+---------+---------+------+

    Kaju, Bhalu and Momo are absent: no visit matches them.

  3. Q33. Names of cats with the dates of their visits, using JOIN and ON.
    Answer
    MySQLquery and result
    SELECT P.PName, V.VDate
    FROM PET P JOIN VISIT V ON P.PID = V.PID
    WHERE P.Species = 'Cat';
    +--------+------------+
    | PName  | VDate      |
    +--------+------------+
    | Mishti | 2026-09-12 |
    | Simba  | 2026-10-12 |
    | Pihu   | 2026-11-09 |
    +--------+------------+

    P and V are table aliases. Once given, use them everywhere in the query.

  4. Q34. How much has been spent on each species?
    Answer
    MySQLquery and result
    SELECT Species, SUM(Fee) FROM PET NATURAL JOIN VISIT
    GROUP BY Species;
    +---------+----------+
    | Species | SUM(Fee) |
    +---------+----------+
    | Dog     |     3100 |
    | Cat     |      700 |
    +---------+----------+

    Rabbits have no visits, so they have no group at all.

  1. Q35. Pets with more than one visit: name, visits and total fee.
    Answer
    MySQLquery and result
    SELECT PName, COUNT(*) AS Visits, SUM(Fee) AS Spent
    FROM PET P, VISIT V WHERE P.PID = V.PID
    GROUP BY PName HAVING COUNT(*) > 1;
    +---------+--------+-------+
    | PName   | Visits | Spent |
    +---------+--------+-------+
    | Biscuit |      2 |   700 |
    | Rocket  |      2 |  2400 |
    +---------+--------+-------+
  2. Q36. Why is this an error? SELECT PID, PName, Vet FROM PET, VISIT WHERE PET.PID = VISIT.PID;
    Answer
    MySQLquery and result
    SELECT PID, PName, Vet FROM PET, VISIT
    WHERE PET.PID = VISIT.PID;
    ERROR 1052 (23000): Column 'PID' in field list is ambiguous

    Both tables have a PID, and MySQL will not choose. Write PET.PID. A natural join would not need it.

  3. Q37. Kaju has never seen a vet, yet this returns seven rows. Why? SELECT PName, Vet FROM PET, VISIT WHERE PName = 'Kaju';
    Answer
    MySQLquery and result
    SELECT PName, Vet FROM PET, VISIT
    WHERE PName = 'Kaju';
    +-------+---------+
    | PName | Vet     |
    +-------+---------+
    | Kaju  | Dr Sen  |
    | Kaju  | Dr Roy  |
    | Kaju  | Dr Sen  |
    | Kaju  | Dr Roy  |
    | Kaju  | Dr Sen  |
    | Kaju  | Dr Roy  |
    | Kaju  | Dr Iyer |
    +-------+---------+

    The join condition was forgotten, so Kaju is paired with all seven visits. A condition on one table is not a join.

  4. Q38. The office adds a Weight column to VISIT, still empty. What does SELECT * FROM PET NATURAL JOIN VISIT; give now, and why?
    Answer
    MySQLquery and result
    ALTER TABLE VISIT ADD Weight FLOAT;
    Query OK, 0 rows affected
    Records: 0  Duplicates: 0  Warnings: 0
    
    SELECT * FROM PET NATURAL JOIN VISIT;
    Empty set

    Two names are shared now, PID and Weight, and both must match. NULL matches nothing. An equi-join on PID would be unharmed.

See the difference in columns

The same two visits, joined both ways. Count the PID headings.

Natural join, 11 columnsMySQL
SELECT * FROM PET NATURAL JOIN VISIT WHERE Reason = 'Injury';
+-----+--------+---------+------+--------+------------+-----+--------+--------+------+------------+
| PID | PName  | Species | AgeM | Weight | Arrived    | VNo | Vet    | Reason | Fee  | VDate      |
+-----+--------+---------+------+--------+------------+-----+--------+--------+------+------------+
| P03 | Rocket | Dog     |   30 |   18.4 | 2026-09-02 | 102 | Dr Roy | Injury | 1500 | 2026-09-03 |
| P03 | Rocket | Dog     |   30 |   18.4 | 2026-09-02 | 106 | Dr Roy | Injury |  900 | 2026-11-06 |
+-----+--------+---------+------+--------+------------+-----+--------+--------+------+------------+
Equi-join, 12 columnsMySQL
SELECT * FROM PET P, VISIT V WHERE P.PID = V.PID AND Reason = 'Injury';
+-----+--------+---------+------+--------+------------+-----+-----+--------+--------+------+------------+
| PID | PName  | Species | AgeM | Weight | Arrived    | VNo | PID | Vet    | Reason | Fee  | VDate      |
+-----+--------+---------+------+--------+------------+-----+-----+--------+--------+------+------------+
| P03 | Rocket | Dog     |   30 |   18.4 | 2026-09-02 | 102 | P03 | Dr Roy | Injury | 1500 | 2026-09-03 |
| P03 | Rocket | Dog     |   30 |   18.4 | 2026-09-02 | 106 | P03 | Dr Roy | Injury |  900 | 2026-11-06 |
+-----+--------+---------+------+--------+------------+-----+-----+--------+--------+------+------------+

To send these queries from a program, continue with Python MySQL connectivity for Class 12. To see them inside a finished application, read the Python and MySQL project.

Now under exam conditions

SQL important questions for Class 12: board-style sets, Questions 39 to 50

Thirty minutes, no computer. The marks beside each question follow the sample paper's sizes; the questions are ours, on the same two tables.

One mark each

  1. Q39. Which clause removes repeated rows from a result?
    (a) UNIQUE
    (b) DISTINCT
    (c) GROUP
    (d) DIFFERENT
    Answer (b) DISTINCT. UNIQUE is a constraint on a column.
  2. Q40. SELECT PName FROM PET WHERE PName LIKE '%o'; returns:
    (a) Rocket and Momo
    (b) Momo
    (c) no rows
    (d) every name with an o
    Answer (b) Momo. Nothing follows the o in the pattern, so the name must end with it.
  3. Q41. Which of these is a DML command?
    (a) ALTER
    (b) CREATE
    (c) UPDATE
    (d) DROP
    Answer (c) UPDATE. It changes rows; the others change structure.
  4. Q42. One visit is deleted. Rows in the cartesian product of PET and VISIT are now:
    (a) 56
    (b) 55
    (c) 48
    (d) 13
    Answer (c) 48, which is 8 x 6.
  5. Q43. Assertion: DELETE FROM PET; removes the table PET from the database. Reason: DROP TABLE removes both the rows and the structure.
    Answer Assertion false, Reason true. DELETE leaves an empty table with its columns in place.
  6. Q44. Which constraint allows NULL but refuses a repeated value?
    (a) PRIMARY KEY
    (b) NOT NULL
    (c) UNIQUE
    (d) CHECK
    Answer (c) UNIQUE.

Two marks each

  1. Q45. Write commands to (I) list all databases on the server, (II) show the columns of VISIT.
    Answer (I) SHOW DATABASES; (II) DESCRIBE VISIT; or DESC VISIT;
  2. Q46. Differentiate between WHERE and HAVING, with an example of each.
    Answer WHERE tests single rows before grouping and cannot hold an aggregate: WHERE Fee > 300. HAVING tests groups after GROUP BY: HAVING SUM(Fee) > 300.
  3. Q47. Differentiate between DDL and DML, with two commands of each.
    Answer DDL defines structure: CREATE TABLE, ALTER TABLE. DML handles the data: INSERT, DELETE.

Four marks each

  1. Q48. On VISIT, predict the output: (I) SELECT Vet, MAX(Fee) FROM VISIT GROUP BY Vet; (II) SELECT PID, Reason FROM VISIT WHERE Vet LIKE '%y%'; (III) SELECT COUNT(PID), COUNT(DISTINCT PID) FROM VISIT; (IV) SELECT SUM(Fee) FROM VISIT WHERE Reason IN ('Vaccine', 'Checkup');
    Answer
    MySQLfour results
    (I)
    +---------+----------+
    | Vet     | MAX(Fee) |
    +---------+----------+
    | Dr Sen  |      400 |
    | Dr Roy  |     1500 |
    | Dr Iyer |     NULL |
    +---------+----------+
    
    (II)
    +-----+---------+
    | PID | Reason  |
    +-----+---------+
    | P03 | Injury  |
    | P05 | Checkup |
    | P03 | Injury  |
    | P07 | Vaccine |
    +-----+---------+
    
    (III)
    +------------+---------------------+
    | COUNT(PID) | COUNT(DISTINCT PID) |
    +------------+---------------------+
    |          7 |                   5 |
    +------------+---------------------+
    
    (IV)
    +----------+
    | SUM(Fee) |
    +----------+
    |     1400 |
    +----------+

    In (II) both Roy and Iyer contain y. Copy the headings too: they are part of the output.

  2. Q49. On VISIT, write queries for: (I) the number of visits for each reason, only where it is above 1; (II) each vet once; (III) visits in November 2026 or later; (IV) visit numbers and fees, highest fee first.
    Answer
    MySQLquery and result
    SELECT Reason, COUNT(*) AS Visits FROM VISIT
    GROUP BY Reason HAVING COUNT(*) > 1;
    +---------+--------+
    | Reason  | Visits |
    +---------+--------+
    | Vaccine |      3 |
    | Injury  |      2 |
    | Checkup |      2 |
    +---------+--------+
    
    SELECT DISTINCT Vet FROM VISIT;
    +---------+
    | Vet     |
    +---------+
    | Dr Sen  |
    | Dr Roy  |
    | Dr Iyer |
    +---------+
    
    SELECT * FROM VISIT WHERE VDate >= '2026-11-01';
    +-----+-----+---------+---------+------+------------+
    | VNo | PID | Vet     | Reason  | Fee  | VDate      |
    +-----+-----+---------+---------+------+------------+
    | 106 | P03 | Dr Roy  | Injury  |  900 | 2026-11-06 |
    | 107 | P07 | Dr Iyer | Vaccine | NULL | 2026-11-09 |
    +-----+-----+---------+---------+------+------------+
    
    SELECT VNo, Fee FROM VISIT ORDER BY Fee DESC;
    +-----+------+
    | VNo | Fee  |
    +-----+------+
    | 102 | 1500 |
    | 106 |  900 |
    | 101 |  400 |
    | 103 |  400 |
    | 104 |  300 |
    | 105 |  300 |
    | 107 | NULL |
    +-----+------+

    NULL comes last in descending order and first in ascending order.

  3. Q50. On both tables, write queries for: (I) raise the fee of every vaccine visit by 50; (II) name and species of pets that arrived in October 2026; (III) visit number, reason and date for Biscuit and Simba; (IV) pet names with vets, in alphabetical order of name.
    Answer
    MySQLquery and result
    UPDATE VISIT SET Fee = Fee + 50 WHERE Reason = 'Vaccine';
    Query OK, 2 rows affected
    Rows matched: 3  Changed: 2  Warnings: 0
    
    SELECT VNo, Fee FROM VISIT WHERE Reason = 'Vaccine';
    +-----+------+
    | VNo | Fee  |
    +-----+------+
    | 101 |  450 |
    | 103 |  450 |
    | 107 | NULL |
    +-----+------+
    
    SELECT PName, Species FROM PET
    WHERE Arrived BETWEEN '2026-10-01' AND '2026-10-31';
    +-------+---------+
    | PName | Species |
    +-------+---------+
    | Simba | Cat     |
    | Bhalu | Dog     |
    +-------+---------+
    
    SELECT V.VNo, V.Reason, V.VDate FROM PET P, VISIT V
    WHERE P.PID = V.PID AND P.PName IN ('Biscuit', 'Simba');
    +-----+---------+------------+
    | VNo | Reason  | VDate      |
    +-----+---------+------------+
    | 101 | Vaccine | 2026-08-10 |
    | 104 | Checkup | 2026-10-12 |
    | 105 | Checkup | 2026-10-30 |
    +-----+---------+------------+
    
    SELECT PName, Vet FROM PET NATURAL JOIN VISIT
    ORDER BY PName;
    +---------+---------+
    | PName   | Vet     |
    +---------+---------+
    | Biscuit | Dr Sen  |
    | Biscuit | Dr Sen  |
    | Mishti  | Dr Sen  |
    | Pihu    | Dr Iyer |
    | Rocket  | Dr Roy  |
    | Rocket  | Dr Roy  |
    | Simba   | Dr Roy  |
    +---------+---------+

    Three rows matched in (I) and two changed: NULL + 50 is NULL. The second query only shows that.

Eight traps, and the habit that beats each

TrapSeen inHabit
= NULLQ19Say "is", write IS NULL
AVG over a column with NULLQ25Count the values, not the rows, before dividing
Aggregate in WHEREQ30If it counts or adds, it goes in HAVING
A column that is neither grouped nor aggregatedQ30Every plain column after SELECT must be in GROUP BY
AND mixed with ORQ22Put brackets round the OR part
Join condition missingQ37Two tables in FROM: write the link before anything else
Shared column without a table nameQ36Prefix every column that both tables have
Natural join on an extra shared columnQ38List the common names before you trust it

Predict, then run

In a one to one class you write the result grid by hand, NULLs included, before the teacher presses Enter. The gap between the two is the lesson.

Four queries in the lab

The practical asks for four queries on one or two tables. We set a fresh pair of tables and you type, test and correct against the clock.

Marked one by one

Each query is right or it is not. The teacher shows which row your version let in or lost, so the same slip is not repeated.

Go further with the Class 12 CS MCQ test, important questions by unit, and a whole paper under time on the 2026-27 sample paper. Spoken SQL answers are in the viva bank.

One to one, at your own timing

SQL improves fastest when somebody sees your query

A wrong query often runs without complaint and returns a believable table, so practice alone can fix a mistake in place. Our SQL classes are personalised one to one only, at a time you set. The priority demo is a complete class you can take before enrolling, and its fee is adjusted against the first month; a free demo class is the shorter look. Fees are monthly, nothing is charged for admission, and you may leave at any month end.

Before you enrol · Try a class

Priority demo, at a slot you pick

a full live class of about 45 to 60 minutes

  • Ten queries on two new tables, to see where you stand
  • Output predicted on paper, then compared with MySQL
  • GROUP BY or joins taught afresh if that is the gap
  • A written skill report naming the clauses to practise
Book a priority demo

The classes · Choose your own timing

Personalised one to one

₹4,999

per month, 4 private classes, fully flexible timing

  • Start at CREATE TABLE or at joins, wherever you need
  • Query sets for your report file, written by you and checked
  • Lab-test practice: four queries, timed
  • Python, files and networks in the same weekly plan
Ask for a personalised plan

MySQL need not be installed for the first class. If it is missing or refuses to start, the teacher helps you set it up, and the practice then happens on your own machine, where the lab test habits are made.

Studying outside India?

SQL classes for 083 students abroad

Whether your CBSE school is in Abu Dhabi, Jeddah or Bangkok, the database unit is the same 20 marks. Pick a morning, an evening or a weekend hour by your own clock.

Where you liveTime differenceUsual class window, local timeFormat
India
every Indian city
Indian timeAny time you choosePersonalised 1-on-1
UAE and Oman
Dubai, Abu Dhabi, Sharjah, Muscat
1 h 30 min behind India3:00 PM to 9:00 PMPersonalised 1-on-1
Saudi Arabia, Qatar, Kuwait, Bahrain
Riyadh, Jeddah, Dammam, Doha, Kuwait City, Manama
2 h 30 min behind India3:00 PM to 9:00 PMPersonalised 1-on-1
Nepal
Kathmandu
15 min ahead of India4:30 PM to 9:00 PMPersonalised 1-on-1
Ethiopia and East Africa
Addis Ababa and East Africa Time
2 h 30 min behind India4:30 PM to 9:00 PMPersonalised 1-on-1
Singapore and Malaysia
Singapore, Kuala Lumpur
2 h 30 min ahead of India3:30 PM to 9:00 PMPersonalised 1-on-1

Typing matters in SQL, so you share your screen and we read the query as you write it. A missed semicolon is noticed on the spot, not a week later.

What families say

Rated 4.9 across 547 Google reviews

Real reviews from real families. We neither write nor commission them.

★★★★★

"The one step solution for my son. Modern Age Coders make learning coding so simple that kids love it. The teachers explain complex concepts clearly with practical exercises and interactive content."

Ria Mukherjee

Parent

★★★★★

"Modern Age Coders has been a game-changer for me. I struggled to grasp IT concepts and coding before joining, but their classes transformed everything. I can now confidently write complex programs with ease."

Samriddha Mondal

Student

★★★★★

"One of the most wonderful education centres out there. Education is not limited to school syllabus but focuses on skill development."

Vansh Agarwal

Student

★★★★★

"My child Dhairya is really enjoying the Modern Age Coders classes. This is his first online class and he eagerly looks forward to it. I can already see his improvement, and the teachers are very cooperative."

Sonam Oswal

Parent of Dhairya

★★★★★

"Modern Age Coders have wonderful teachers who teach in a clear, easy and practical way. The teacher boosts students' confidence and inspires them to learn without hesitation."

Sonu Goyal

Parent

★★★★★

"I highly recommend this computer coding class! The teachers are incredibly knowledgeable and passionate about coding."

Ritu Kedia

Parent

The rest of the Class 12 series

More pages for Class 12 students

Every page in the CBSE Class 12 Computer Science series, grouped by what you need.

SQL questions, answered

What Class 12 students ask about SQL

How many marks is SQL in Class 12 Computer Science?

Database Management is 20 of the 70 theory marks in CBSE 083 for 2026-27. In the sample paper, 4 of those 20 are for a Python-MySQL program and 16 for SQL and relational theory. The practical adds 4 marks for SQL queries in the lab test.

Which SQL queries are important for Class 12 Computer Science?

GROUP BY with HAVING, aggregates on a column that has NULL, LIKE patterns, BETWEEN and IN, ORDER BY on two columns, UPDATE, ALTER TABLE for a column or primary key, and an equi-join of two tables with a condition. The sample paper uses most of these in Questions 27, 32 and 34.

What is the difference between equi-join and natural join in Class 12?

An equi-join needs the condition written out and, with SELECT *, shows the common column twice. A natural join matches every column name the two tables share and shows each once. On our tables the first gives 12 columns, the second 11.

What is the difference between WHERE and HAVING in SQL?

WHERE filters single rows before they are grouped, so it cannot contain COUNT, SUM, AVG, MAX or MIN. HAVING filters groups after GROUP BY and usually does contain one. A query may use both, with WHERE written first.

Are subqueries, views or outer joins in the Class 12 CS syllabus?

They are not listed in the 083 syllabus for 2026-27. The joins named are cartesian product, equi-join and natural join. Questions such as "pets that never visited" need an outer join or a subquery, so they are outside what is named.

Is SQL case sensitive in the CBSE exam?

Keywords such as SELECT may be typed in any case in MySQL. Write keywords in capitals for clarity and copy table and column names as the question spells them. Keep text values exactly as given, since you cannot be sure how a comparison treats case.

What is the order of clauses in a SELECT query?

SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY. Any of the last four may be absent, but they may not change places. MySQL works them out in a different order: FROM and WHERE first, then groups, then SELECT, then sorting.

Do I have to write the output table with headings?

Yes, write the column headings exactly as the query would show them, including an alias or a heading such as MAX(Fee). Write NULL where the value is missing, not a blank or a zero.

Is SQL in Computer Science the same as in Informatics Practices?

No. IP (065) adds math, text and date functions and gives SQL 25 theory marks. CS (083) has no such functions but adds natural join and the Python interface. SELECT, GROUP BY, HAVING and equi-join are common to both.

How can I practise SQL queries for Class 12 with a teacher?

Modern Age Coders teaches 083 SQL live and personalised one to one at your own timing. Book a priority demo for a full class of about 45 to 60 minutes with a written skill report; its fee is adjusted against the first month if you enrol. A free demo class is available as well.

Start

Write ten queries. See which ones fail.

The free demo class is enough to try a few queries on a table you have not seen and find out whether SELECT, grouping or joins is the weak step.

The priority demo goes the full distance: ten queries, the failed ones rebuilt with a teacher, and a written skill report. You choose the slot, and the fee is adjusted against the first month if you enrol.

New to both SQL and Python? The practical file guide shows what your school will want to see from each.

WhatsApp us · +91 91233 66161 · connect@modernagecoders.com

Every class is live video. The form requests a callback and reserves nothing.

We call within a few hours. No card, no enrolment fee.

Want it sooner? Book a priority demo

A full live class of about 45 to 60 minutes at a slot you pick, with a written skill report and learning roadmap on WhatsApp afterwards. The fee is adjusted against your first month if you enrol.

Book a priority demo

Keep exploring Modern Age Coders

By class and age

Learn more

Free resources

From the blog

Start here