0% found this document useful (0 votes)
8 views3 pages

SQL 1 (12th)

The document outlines a Grade 12 periodic test covering the Relational Data Model, SQL commands, and Python-SQL interface. It includes theoretical questions about database concepts, SQL queries for data manipulation, and Python scripts for database interaction. The test is structured into three sections, with a total of 35 marks available.

Uploaded by

pdfcliff
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

SQL 1 (12th)

The document outlines a Grade 12 periodic test covering the Relational Data Model, SQL commands, and Python-SQL interface. It includes theoretical questions about database concepts, SQL queries for data manipulation, and Python scripts for database interaction. The test is structured into three sections, with a total of 35 marks available.

Uploaded by

pdfcliff
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Section A: Theory (15 Marks)

Q1. Define a Relational Data Model. Explain the terms Relation, Attribute, Tuple, and Domain. (4 Marks)
Q2. Differentiate between Primary Key and Foreign Key. Provide an example for each. (3 Marks)
Q3. Explain any three SQL constraints. Provide examples to demonstrate their use. (3 Marks)
Q4. Explain the following SQL commands with syntax and examples: (5 Marks)
a. ALTER TABLE (to add/remove attributes)
b. GROUP BY with HAVING clause
Section B: SQL Queries (12 Marks)
Q5. Consider the following table Students:
RollNo Name Age Marks
1 Aman 18 85
2 Bhavya 19 90
3 Charu 18 75
4 Divya 17 80
Write SQL queries for the following:
a. Retrieve names of students who scored more than 80 marks. (1 Mark)
b. Display the student details sorted by Age in ascending order. (1 Mark)
c. Find the average marks of students. (1 Mark)
d. Update the Marks of Bhavya to 95. (1 Mark)
Q6. Write the SQL query to create a table named Employees with the following structure:
 EmpID (integer, primary key)
 Name (varchar(50), not null)
 Salary (float)
 Department (varchar(20))
(2 Marks)
Q7. Using the table Employees, write SQL commands to:
a. Insert a record with values (101, 'Raj', 55000, 'HR').
b. Delete the record of an employee with EmpID = 101.
(2 Marks)
Q8. Explain the difference between IS NULL and IS NOT NULL with examples. (2 Marks)
Section C: Python-SQL Interface (8 Marks)
Q9. Write a Python script to connect to an SQL database named School and create a table Subjects with
columns: SubID (integer, primary key), SubName (varchar(30)). (4 Marks)
Q10. Explain the following Python-SQL methods:
a. execute()
b. fetchall()
c. commit()
d. rowcount
(4 Marks)
Answer Key: Grade 12 Periodic Test 1 (35 Marks)

Section A: Theory (15 Marks)


Q1. (4 Marks)
 Relational Data Model: Organizes data into one or more tables (relations) of rows and columns, with a
unique key identifying each row.
 Relation: A table.
 Attribute: A column in a table.
 Tuple: A row in a table.
 Domain: The set of allowable values for an attribute.
Q2. (3 Marks)
 Primary Key: A unique identifier for each record in a table (e.g., RollNo).
 Foreign Key: An attribute that links to the primary key of another table.
Example:
 Primary Key: RollNo in the Students table.
 Foreign Key: DeptID in Employees referencing Departments.
Q3. (3 Marks)
 NOT NULL: Ensures a column cannot have NULL values.
 UNIQUE: Ensures all values in a column are unique.
 PRIMARY KEY: Combines NOT NULL and UNIQUE for identifying records.
Example:
CREATE TABLE Students (
RollNo INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
Age INT UNIQUE
);
Q4. (5 Marks)
 ALTER TABLE:
Add: ALTER TABLE Employees ADD Bonus FLOAT;
Remove: ALTER TABLE Employees DROP COLUMN Bonus;
 GROUP BY with HAVING:
SELECT DeptID, AVG(Salary)
FROM Employees
GROUP BY DeptID
HAVING AVG(Salary) > 50000;
Section B: SQL Queries (12 Marks)
Q5. (4 Marks)
a. SELECT Name FROM Students WHERE Marks > 80;
b. SELECT * FROM Students ORDER BY Age ASC;
c. SELECT AVG(Marks) AS AvgMarks FROM Students;
d. UPDATE Students SET Marks = 95 WHERE Name = 'Bhavya';
Q6. (2 Marks)
CREATE TABLE Employees (
EmpID INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
Salary FLOAT,
Department VARCHAR(20)
);
Q7. (2 Marks)
a. INSERT INTO Employees VALUES (101, 'Raj', 55000, 'HR');
b. DELETE FROM Employees WHERE EmpID = 101;
Q8. (2 Marks)
 IS NULL: Finds rows where a column has NULL value.
Example: SELECT * FROM Students WHERE Marks IS NULL;
 IS NOT NULL: Finds rows where a column has non-NULL value.
Example: SELECT * FROM Students WHERE Marks IS NOT NULL;
Section C: Python-SQL Interface (8 Marks)
Q9. (4 Marks)
import mysql.connector
db = mysql.connector.connect(host="localhost", user="root", password="password",
database="School")
cursor = db.cursor()
cursor.execute("CREATE TABLE Subjects (SubID INT PRIMARY KEY, SubName VARCHAR(30));")
db.close()
Q10. (4 Marks)
 execute(): Executes an SQL command.
 fetchall(): Retrieves all rows of a query result.
 commit(): Saves changes to the database.
 rowcount: Returns the number of affected rows.

You might also like