MBOSE Class XII Computer Science · Chapter 9
Structured Query Language (SQL)
Opening soonLearn to create, change and question databases with SQL commands, and connect a Python program to a MySQL database.
19 lessons · 56 practice questions · unit "Database Management" carries 20 marks
What this chapter covers
- SQL and MySQL
- Data types
- Constraints
- DDL — CREATE, USE, SHOW, DESCRIBE, ALTER, DROP
- DML — INSERT, UPDATE, DELETE
- SELECT with WHERE, DISTINCT, aliases, BETWEEN, IN, LIKE, IS NULL, ORDER BY
- Single-row and aggregate functions
- GROUP BY and HAVING
- Set operations
- Cartesian product and joins
- Python–MySQL connectivity
Key terms
- SQL
Language for creating and querying relational databases
- DDL
Commands that define structure (CREATE, ALTER, DROP)
- DML
Commands that change data (INSERT, UPDATE, DELETE)
- Constraint
Rule restricting the values of a column
- Clause
Part of a SQL statement (WHERE, ORDER BY…)
- Aggregate function
Function returning one value for a group of rows
- GROUP BY
Groups rows with the same value
- HAVING
Condition on groups
- Join
Combining rows of two tables on a related column
- Equi-join
Join using the = operator
- Cursor
Object that executes queries and holds results in Python
Important questions with answers
10 of the 56 questions on this chapter, solved.
Question 1 · Multiple choice · 1 mark
Which command creates a table?
- (a) CREATE TABLE
- (b) MAKE TABLE
- (c) NEW TABLE
- (d) INSERT TABLE
Answer: (a) CREATE TABLE
It is a DDL command.
Question 2 · Multiple choice · 1 mark
Which constraint allows no duplicate values but allows NULL?
- (a) PRIMARY KEY
- (b) NOT NULL
- (c) DEFAULT
- (d) UNIQUE
Answer: (d) UNIQUE
A primary key cannot be NULL.
Question 3 · Multiple choice · 1 mark
ROUND(342.9234, -1)gives- (a) 340
- (b) 342.9
- (c) 343
- (d) 300
Answer: (a) 340
Rounded to the nearest ten.
Question 4 · Multiple choice · 1 mark
COUNT(*) counts
- (a) all rows
- (b) non-NULL values
- (c) distinct values
- (d) columns
Answer: (a) all rows
COUNT(col) skips NULLs.
Question 5 · Assertion and reason · 1 mark
Assertion (A):
WHERE grade = NULLreturns no rows.Reason (R): NULL must be tested with IS NULL.
- (a) Both A and R are true, and R is the correct explanation of A.
- (b) Both A and R are true, but R is not the correct explanation of A.
- (c) A is true, but R is false.
- (d) A is false, but R is true.
Answer: (a) Both A and R are true, and R is the correct explanation of A.
Comparing with = NULL is never true.
Question 6 · Short answer · 2 marks
Distinguish DDL and DML with one example each.
Answer
DDL defines structure (CREATE); DML changes data (INSERT).
Question 7 · Short answer · 2 marks
What does cursor() do in Python–MySQL?
Answer
It creates a cursor object through which queries are executed and results fetched.
Question 8 · Short answer · 3 marks
Distinguish single-row and aggregate functions.
Answer
Single-row: one result per row (UPPER); aggregate: one result per group (SUM).
Question 9 · Long answer · 5 marks
Explain the DDL commands with examples.
Answer
Section 1.3; Exercise Q4.
Question 10 · Long answer · 5 marks
Explain joins with an example of an equi-join.
Answer
Section 1.9; Section 8.2 (HSSLC 2023, Q8(b)).
Study the whole chapter
19 step-by-step lessons, all 56 practice questions with hints, flashcards and mock tests for MBOSE Class XII Computer Science.