Skip to main content
Chapter 1 of 7
NCERT Solutions

Querying and SQL Functions — NCERT Solutions

CBSE · Class 12 · Informatics Practices

NCERT question answers for Querying and SQL Functions, CBSE Class 12 Informatics Practices: 42 textbook questions solved step by step. Covers Exercise.

111 questions84 flashcards4 formulas & key relations5 concepts

Interactive on Super Tutor

Studying Querying and SQL Functions? Get the full interactive chapter.

Quizzes, flashcards, AI doubt-solver and a step-by-step study plan — built for NCERT solutions and more.

Free trial, no card needed.

42 Questions Solved · 1 Section

The first 21 solutions are open to read. The other 21 are free with a Super Tutor account. Unlock all 42 free in Super Tutor

Exercise

1aDefine RDBMS. Name any two RDBMS software.Show solution

An RDBMS is a Relational Database Management System. It stores data in the form of related tables (relations) and manages relationships among them.

Two examples are MySQL and Oracle.

Not sure why a step works? check your working in Super Tutor

1b(i)What is the purpose of the following clauses in a select statement?

i) ORDER BY

Show solution

ORDER BY clause का उपयोग परिणामों को क्रमबद्ध करने के लिए किया जाता है। इसके द्वारा रिकॉर्ड्स को ascending या descending क्रम में दिखाया जा सकता है।

Not sure why a step works? check your working in Super Tutor

1cSite any two differences between Single_row functions and Aggregate functions.Show solution

Any two differences are:

  1. Single row functions work on a single row at a time, while aggregate functions work on a group of rows.
  2. Single row functions return one result per row, while aggregate functions return one result for the whole group.
  3. Single row functions can be used in SELECT, WHERE, and ORDER BY, while aggregate functions are used in the SELECT clause only.

Not sure why a step works? check your working in Super Tutor

1dWhat do you understand by Cartesian Product?Show solution

Cartesian Product is an operation that combines tuples from two relations and produces all possible pairs of rows from the two tables, regardless of whether the values match or not.

If one table has mm rows and the other has nn rows, the result has m×nm \times n rows.

Not sure why a step works? check your working in Super Tutor

1e(i)Write the name of the functions to perform the following operations:

i) To display the day like “Monday”, “Tuesday”, from the date when India got independence.

Show solution

सप्ताह के दिन का नाम जैसे Monday, Tuesday आदि दिखाने के लिए DAYNAME() function का उपयोग किया जाता है।

Not sure why a step works? check your working in Super Tutor

1e(ii)Write the name of the functions to perform the following operations:

ii) To display the specified number of characters from a particular position of the given string.

Show solution

किसी string के निर्दिष्ट position से निर्दिष्ट number of characters निकालने के लिए MID() function का उपयोग किया जाता है।

Not sure why a step works? check your working in Super Tutor

1e(iii)Write the name of the functions to perform the following operations:

iii) To display the name of the month in which you were born.

Show solution

जिस month में जन्म हुआ है उसका नाम दिखाने के लिए MONTHNAME() function का उपयोग किया जाता है।

Not sure why a step works? check your working in Super Tutor

1e(iv)Write the name of the functions to perform the following operations:

iv) To display your name in capital letters.

Show solution

नाम को capital letters में दिखाने के लिए UPPER() function का उपयोग किया जाता है।

Not sure why a step works? check your working in Super Tutor

2aSELECT POW(2,3);Show solution

POW(2,3) means 232^3.

2×2×2=82 \times 2 \times 2 = 8

So the output is 8.

Not sure why a step works? check your working in Super Tutor

2bSELECT ROUND(123.2345, 2), ROUND(342.9234,-1);Show solution
  • ROUND(123.2345, 2) rounds to 123.23.
  • ROUND(342.9234, -1) rounds to the nearest tens, so it becomes 340.

So the output is 123.23, 340.

Not sure why a step works? check your working in Super Tutor

2cSELECT LENGTH("Informatics Practices");Show solution

LENGTH("Informatics Practices") counts all characters including the space.

  • Informatics = 11
  • space = 1
  • Practices = 9

Total = 11+1+9=2111 + 1 + 9 = 21

So the output is 21.

Not sure why a step works? check your working in Super Tutor

2dSELECT YEAR("1979/11/26"),
MONTH("1979/11/26"),
DAY("1979/11/26"),

MONTHNAME("1979/11/26");
Show solution

From "1979/11/26":

  • YEAR() = 1979
  • MONTH() = 11
  • DAY() = 26
  • MONTHNAME() = November

So the output is 1979, 11, 26, November.

Not sure why a step works? check your working in Super Tutor

2eSELECT LEFT("INDIA",3), RIGHT("Computer Science",4);Show solution
  • LEFT("INDIA",3) gives IND.
  • RIGHT("Computer Science",4) gives ence.

So the output is IND, ence.

The printed text in the question pairs this with the values from the chapter-style format; the correct result from the SQL command is IND, ence.

Not sure why a step works? check your working in Super Tutor

2fSELECT MID("Informatics",3,4), SUBSTR("Practices",3);Show solution
  • MID("Informatics",3,4) starts from position 3 and takes 4 characters: form.
  • SUBSTR("Practices",3) starts from position 3 till the end: actices.

So the output is form, actices.

Not sure why a step works? check your working in Super Tutor

3a(i)Write SQL queries for the following:

i. Create the table Product with appropriate data types and constraints.

Show solution
CREATE TABLE Product (
    PCode VARCHAR(3) PRIMARY KEY,
    PName VARCHAR(30),
    UPrice NUMERIC(10,2),
    Manufacturer VARCHAR(20)
);

Not sure why a step works? check your working in Super Tutor

3a(ii)Write SQL queries for the following:

ii. Identify the primary key in Product.

Show solution

Product table की primary key PCode है।

Not sure why a step works? check your working in Super Tutor

3a(iii)Write SQL queries for the following:

iii. List the Product Code, Product name and price in descending order of their product name. If PName is the same then display the data in ascending order of price.

Show solution
SELECT PCode, PName, UPrice
FROM Product
ORDER BY PName DESC, UPrice ASC;

Not sure why a step works? check your working in Super Tutor

3a(iv)Write SQL queries for the following:

iv. Add a new column Discount to the table Product.

Show solution
ALTER TABLE Product ADD Discount NUMERIC(10,2);

Not sure why a step works? check your working in Super Tutor

3a(vii)Write SQL queries for the following:

vii. Display the total number of products manufactured by each manufacturer.

Show solution

To display the total number of products manufactured by each manufacturer, we group the rows by Manufacturer and use *COUNT()** to count products in each group.

SELECT Manufacturer, COUNT(*)
FROM Product
GROUP BY Manufacturer;

Not sure why a step works? check your working in Super Tutor

3b(i)Write the output(s) produced by executing the following queries on the basis of the information given above in the table Product:

i. SELECT PName, Average(UPrice) FROM Product GROUP BY Pname;

Show solution

The query uses Average(UPrice), but the chapter lists the aggregate function as AVG(UPrice). So the intended query would use AVG(UPrice).

For the given table:

  • Soap appears twice with prices 2525 and 3838, so average =(25+38)/2=31.5= (25+38)/2 = 31.5
  • The other product names occur once, so their average is their only price

Output would be:

PNameAVG(UPrice)
Washing Powder120
Tooth Paste59.5
Soap31.5
Shampoo245

Not sure why a step works? check your working in Super Tutor

3b(ii)Write the output(s) produced by executing the following queries on the basis of the information given above in the table Product:

ii. SELECT DISTINCT Manufacturer FROM Product;

Show solution

DISTINCT removes repeated manufacturer names. From the table, the unique manufacturers are:

  • Surf
  • Colgate
  • Lux
  • Pepsodant
  • Dove

So the output is:

Manufacturer
Surf
Colgate
Lux
Pepsodant
Dove

Not sure why a step works? check your working in Super Tutor

3b(iii)Write the output(s) produced by executing the following queries on the basis of the information given above in the table Product:

iii. SELECT COUNT(DISTINCT PName) FROM Product;

Free with a Super Tutor account

3b(iv)Write the output(s) produced by executing the following queries on the basis of the information given above in the table Product:

iv. SELECT PName, MAX(UPrice), MIN(UPrice) FROM Product GROUP BY PName;

Free with a Super Tutor account

4aUsing the CARSHOWROOM database given in the chapter, write the SQL queries for the following:

a) Add a new column Discount in the INVENTORY table.

Free with a Super Tutor account

4b(i)Using the CARSHOWROOM database given in the chapter, write the SQL queries for the following:

b) Set appropriate discount values for all cars keeping in mind the following:

(i) No discount is available on the LXI model.

Free with a Super Tutor account

4b(ii)Using the CARSHOWROOM database given in the chapter, write the SQL queries for the following:

b) Set appropriate discount values for all cars keeping in mind the following:

(ii) VXI model gives a 10% discount.

Free with a Super Tutor account

4b(iii)Using the CARSHOWROOM database given in the chapter, write the SQL queries for the following:

b) Set appropriate discount values for all cars keeping in mind the following:

(iii) A 12% discount is given on cars other than LXI model and VXI model.

Free with a Super Tutor account

4cUsing the CARSHOWROOM database given in the chapter, write the SQL queries for the following:

c) Display the name of the costliest car with fuel type “Petrol”.

Free with a Super Tutor account

4dUsing the CARSHOWROOM database given in the chapter, write the SQL queries for the following:

d) Calculate the average discount and total discount available on Car4.

Free with a Super Tutor account

4eUsing the CARSHOWROOM database given in the chapter, write the SQL queries for the following:

e) List the total number of cars having no discount.

Free with a Super Tutor account

5aWrite SQL queries for the following:

a) Create the database Streams_Of_Students.

Free with a Super Tutor account

5bWrite SQL queries for the following:

b) Create the table Student by choosing appropriate data types based on the data given in the table.

Free with a Super Tutor account

5cWrite SQL queries for the following:

c) Identify the Primary keys from tables Student and Stream. Also, identify the foreign key from the table Stream.

Free with a Super Tutor account

5dWrite SQL queries for the following:

d) Jay has now changed his stream to Humanities. Write an appropriate SQL query to reflect this change.

Free with a Super Tutor account

5eWrite SQL queries for the following:

e) Display the names of students whose names end with the character 'a'. Also, arrange the students in alphabetical order.

Free with a Super Tutor account

5fWrite SQL queries for the following:

f) Display the names of students enrolled in Science and Humanities stream, ordered by student name in alphabetical order, then by admission number in ascending order (for duplicating names).

Free with a Super Tutor account

5gWrite SQL queries for the following:

g) List the number of students in each stream having more than 1 student.

Free with a Super Tutor account

5hWrite SQL queries for the following:

h) Display the names of students enrolled in different streams, where students are arranged in descending order of admission number.

Free with a Super Tutor account

5iWrite SQL queries for the following:

i) Show the Cartesian product on the Student and Stream table. Also mention the degree and cardinality produced after applying the Cartesian product.

Free with a Super Tutor account

5jWrite SQL queries for the following:

j) Add a new column 'TeacherIncharge' in the Stream table. Insert appropriate data in each row.

Free with a Super Tutor account

5kWrite SQL queries for the following:

k) List the names of teachers and students.

Free with a Super Tutor account

5lWrite SQL queries for the following:

l) If Cartesian product is again applied on Student and Stream tables, what will be the degree and cardinality of this modified table?

Free with a Super Tutor account

21 more solved questions in Querying and SQL Functions

They are free with a Super Tutor account, along with practice quizzes and flashcards for this chapter. Free to start, no card needed.

Frequently Asked Questions

What are the important topics in Querying and SQL Functions for CBSE Class 12 Informatics Practices?
Key topics in Querying and SQL Functions include SQL Functions, String and Date Functions, Aggregate Functions and GROUP BY, Operations on Relations. Study these first, then practise questions on each for the CBSE Class 12 board exam.
Are these NCERT Solutions for Querying and SQL Functions free?
The first 21 of the 42 solutions on this page are open to read. The other 21 are free with a Super Tutor account — signing up is free and needs no card.
How should I revise Querying and SQL Functions for the CBSE Class 12 board exam?
Learn the core ideas first, then work through the 111 practice questions on Querying and SQL Functions. Revise definitions regularly and use flashcards for quick recall before the exam.

Sources & Official References

Content is aligned to the official syllabus. Refer to the board website for the latest curriculum.

For serious students

Get the full Querying and SQL Functions chapter — start free.

Quizzes, flashcards, an AI doubt solver and a study plan for CBSE Class 12 Informatics Practices. Free to start, no card needed.