SQL-2(12th)
SQL-2(12th)
Q1. What is the significance of a candidate key? How does it differ from a primary key? Give examples. (3
Marks)
Q2. Define degree and cardinality in the context of a relational database. Illustrate with an example. (2 Marks)
Q3. Explain the role of foreign keys in maintaining relationships between tables. How does it enforce referential
integrity? Provide an example. (3 Marks)
Q4. Describe the following SQL clauses with examples:
a. DISTINCT
b. ORDER BY
c. LIKE (pattern matching)
(6 Marks)
Q5. Explain the differences between DDL and DML commands with examples of at least two commands from
each category. (3 Marks)
Q6. Write a short note on aggregate functions in SQL. Explain with examples. (3 Marks)
Section B: SQL Queries (20 Marks)
Q7. Consider the following tables:
Table 1: Employees
EmpID Name DeptID Salary
1 Aman 101 50000
2 Bhavya 102 60000
3 Charu 101 55000
Table 2: Departments
DeptID DeptName Location
101 HR Mumbai
102 IT Delhi
Write SQL queries for the following:
a. Retrieve the names of employees working in the "HR" department. (2 Marks)
b. Find the total salary paid to employees in each department. (2 Marks)
c. Display all employee names along with their department names using a join operation. (3 Marks)
d. Add a new column Bonus (float) to the Employees table. (1 Mark)
Q8. Write the SQL command to:
a. Create a database named Company.
b. Use the database Company.
c. Drop the database Company.
(3 Marks)
Q9. Using the Employees table, write SQL commands to:
a. Insert a new record with values (4, 'Divya', 103, 45000).
b. Update the Salary of Bhavya to 65000.
c. Delete the record of an employee with EmpID = 3.
(3 Marks)
Q10. Write an SQL query to:
a. Retrieve the details of employees whose salary is between 45000 and 60000.
b. Display the details of employees who do not belong to the "IT" department.
c. Retrieve distinct department names from the Departments table.
(3 Marks)
Q11. Write SQL queries to demonstrate the use of:
a. IS NULL and IS NOT NULL
b. HAVING clause with GROUP BY
(3 Marks)
Section C: Python-SQL Interface (10 Marks)
Q12. Write a Python program to perform the following operations using MySQL:
a. Connect to a database named Library.
b. Create a table Books with columns: BookID (int, primary key), Title (varchar(100)), Author (varchar(50)).
c. Insert a record into the Books table.
(5 Marks)
Q13. Explain the following Python-SQL terms with examples:
a. fetchone() vs. fetchall()
b. Role of the cursor() object in database connectivity
(3 Marks)
Q14. A database table Sales contains the following columns: SaleID, Product, Quantity, and Amount. Write a
Python script to retrieve and display all records from this table using a SQL query. (2 Marks)
Answer Key: Grade 12 Periodic Test 2 (50 Marks)