0% found this document useful (0 votes)
25 views9 pages

Relational Databases

This guide provides an overview of relational databases for Class 12 CBSE (2025-26), focusing on SQL operations such as creating, querying, updating, and deleting data. It includes key concepts, syntax examples, and practical SQL programs to enhance student understanding. Additionally, the guide emphasizes best practices and concludes with a comprehensive program that integrates all learned SQL commands.

Uploaded by

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

Relational Databases

This guide provides an overview of relational databases for Class 12 CBSE (2025-26), focusing on SQL operations such as creating, querying, updating, and deleting data. It includes key concepts, syntax examples, and practical SQL programs to enhance student understanding. Additionally, the guide emphasizes best practices and concludes with a comprehensive program that integrates all learned SQL commands.

Uploaded by

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

Complete Guide to Relational Databases for Class 12

CBSE 2025-26

August 8, 2025

1 Introduction to Relational Databases


A relational database organizes data in tables with rows (records) and columns (fields).
Tables are linked using keys. For Class 12 CBSE (2025-26), the NCERT syllabus covers
SQL for creating, querying, updating, and deleting data in relational databases. This
guide provides theory, simple SQL programs, output-based questions, and a final program
combining all queries, ensuring clear understanding for students.

1.1 Why Relational Databases are Important


• Organize data systematically.

• Enable efficient data retrieval and updates using SQL.

• Maintain data accuracy with keys.

• Used in applications like school management and online systems.

2 Key Concepts
The NCERT syllabus includes:

• Database: A collection of related data.

• Table: A set of rows and columns storing data.

• Keys:

– Primary Key: Uniquely identifies each record.


– Candidate Key: A column that could be a primary key.
– Foreign Key: Links two tables (not used in programs here).

• SQL: Language for database operations.

– DDL (Data Definition Language): CREATE, ALTER, DROP.


– DML (Data Manipulation Language): INSERT, UPDATE, DELETE, SELECT.

1
3 Syntax and Examples
Below are simple SQL programs covering all NCERT syllabus operations, with clear expla-
nations and outputs. Programs use a table student (columns: rollno INTEGER PRI-
MARY KEY, name VARCHAR(20), marks INTEGER) and a table teacher (columns:
tid INTEGER PRIMARY KEY, name VARCHAR(20), subject VARCHAR(20)).

3.1 Program 1: Creating a Student Table


1 CREATE TABLE student (
2 rollno INTEGER PRIMARY KEY ,
3 name VARCHAR (20) ,
4 marks INTEGER
5 );

Explanation:

1. CREATE TABLE student: Creates a table named student.

2. Columns:

• rollno: Unique integer (primary key).


• name: String up to 20 characters.
• marks: Integer for marks.

Output: (No output; table is created.)

3.2 Program 2: Creating a Teacher Table


1 CREATE TABLE teacher (
2 tid INTEGER PRIMARY KEY ,
3 name VARCHAR (20) ,
4 subject VARCHAR (20)
5 );

Explanation:

1. CREATE TABLE teacher: Creates a table named teacher.

2. Columns:

• tid: Unique integer (primary key).


• name: String up to 20 characters.
• subject: String for subject taught.

Output: (No output; table is created.)

2
3.3 Program 3: Inserting Student Records
1 INSERT INTO student VALUES
2 (101 , ’ Anita ’ , 85) ,
3 (102 , ’ Ravi ’ , 90) ,
4 (103 , ’ Suman ’ , 75) ;

Explanation:

1. INSERT INTO student VALUES: Adds records to student.

2. Each record includes rollno, name, marks.

3. Three students are added.

Output: (No output; records are added.)

3.4 Program 4: Inserting Teacher Records


1 INSERT INTO teacher VALUES
2 (1 , ’ Meena ’ , ’ Math ’) ,
3 (2 , ’ Arun ’ , ’ Science ’) ;

Explanation:

1. INSERT INTO teacher VALUES: Adds records to teacher.

2. Each record includes tid, name, subject.

3. Two teachers are added.

Output: (No output; records are added.)

3.5 Program 5: Selecting Student Records


1 SELECT * FROM student WHERE marks >= 80;

Explanation:

1. SELECT *: Retrieves all columns (rollno, name, marks).

2. FROM student: Targets student table.

3. WHERE marks >= 80: Filters records with marks 80 or higher.

Output (After Program 3):

+--------+-------+-------+
| rollno | name | marks |
+--------+-------+-------+
| 101 | Anita | 85 |
| 102 | Ravi | 90 |
+--------+-------+-------+

3
3.6 Program 6: Selecting with Sorting
1 SELECT * FROM student ORDER BY marks DESC ;

Explanation:

1. SELECT *: Retrieves all columns.

2. FROM student: Targets student table.

3. ORDER BY marks DESC: Sorts records by marks in descending order.

Output (After Program 3):

+--------+-------+-------+
| rollno | name | marks |
+--------+-------+-------+
| 102 | Ravi | 90 |
| 101 | Anita | 85 |
| 103 | Suman | 75 |
+--------+-------+-------+

3.7 Program 7: Selecting with Multiple Conditions


1 SELECT * FROM student WHERE marks >= 80 AND name LIKE ’A % ’;

Explanation:

1. SELECT *: Retrieves all columns.

2. FROM student: Targets student table.

3. WHERE marks >= 80 AND name LIKE ’A%’: Filters records with marks 80 or higher
and name starting with ’A’.

Output (After Program 3):

+--------+-------+-------+
| rollno | name | marks |
+--------+-------+-------+
| 101 | Anita | 85 |
+--------+-------+-------+

3.8 Program 8: Selecting with OR Condition


1 SELECT * FROM teacher WHERE subject = ’ Math ’ OR subject = ’
Science ’;

Explanation:

1. SELECT *: Retrieves all columns (tid, name, subject).

2. FROM teacher: Targets teacher table.

4
3. WHERE subject = ’Math’ OR subject = ’Science’: Filters records where subject
is ’Math’ or ’Science’.

Output (After Program 4):

+-----+-------+---------+
| tid | name | subject |
+-----+-------+---------+
| 1 | Meena | Math |
| 2 | Arun | Science |
+-----+-------+---------+

3.9 Program 9: Updating Student Marks


1 UPDATE student SET marks = 80 WHERE rollno = 103;

Explanation:

1. UPDATE student: Targets student table.

2. SET marks = 80: Sets marks to 80.

3. WHERE rollno = 103: Updates only the record with rollno 103.

Output: (No output; record is updated.)

3.10 Program 10: Updating Multiple Columns


1 UPDATE student SET marks = 88 , name = ’ Priya ’ WHERE rollno = 101;

Explanation:

1. UPDATE student: Targets student table.

2. SET marks = 88, name = ’Priya’: Updates marks and name.

3. WHERE rollno = 101: Updates only the record with rollno 101.

Output: (No output; record is updated.)

3.11 Program 11: Deleting Student Records


1 DELETE FROM student WHERE marks < 80;

Explanation:

1. DELETE FROM student: Removes records from student.

2. WHERE marks < 80: Deletes records with marks below 80.

Output: (No output; records are deleted.)

5
3.12 Program 12: Deleting All Teacher Records
1 DELETE FROM teacher ;

Explanation:

1. DELETE FROM teacher: Removes all records from teacher.

2. No WHERE clause means all records are deleted.

Output: (No output; all records are deleted.)

3.13 Program 13: Altering Student Table


1 ALTER TABLE student ADD class VARCHAR (10) ;

Explanation:

1. ALTER TABLE student: Modifies student table.

2. ADD class VARCHAR(10): Adds a class column (up to 10 characters).

Output: (No output; table structure is updated.)

3.14 Program 14: Modifying Column Type


1 ALTER TABLE teacher MODIFY subject VARCHAR (30) ;

Explanation:

1. ALTER TABLE teacher: Modifies teacher table.

2. MODIFY subject VARCHAR(30): Changes subject column to allow up to 30 char-


acters.

Output: (No output; column type is updated.)

3.15 Program 15: Combined SQL Script for School Database


1 -- Create tables
2 CREATE TABLE student (
3 rollno INTEGER PRIMARY KEY ,
4 name VARCHAR (20) ,
5 marks INTEGER
6 );
7 CREATE TABLE teacher (
8 tid INTEGER PRIMARY KEY ,
9 name VARCHAR (20) ,
10 subject VARCHAR (20)
11 );
12

13 -- Insert records

6
14 INSERT INTO student VALUES (101 , ’ Anita ’ , 85) ;
15 INSERT INTO student ( rollno , name ) VALUES (102 , ’ Ravi ’) ;
16 INSERT INTO teacher VALUES (1 , ’ Meena ’ , ’ Math ’) ;
17

18 -- Select records
19 SELECT * FROM student WHERE marks >= 80 OR name LIKE ’A % ’;
20 SELECT * FROM teacher ORDER BY name ;
21

22 -- Update records
23 UPDATE student SET marks = 90 WHERE rollno = 102;
24

25 -- Delete records
26 DELETE FROM student WHERE marks IS NULL ;
27

28 -- Alter table
29 ALTER TABLE student ADD class VARCHAR (10) ;
30

31 -- Drop table
32 DROP TABLE teacher ;

Explanation:
1. Create: Creates student and teacher tables.

2. Insert: Adds two student records (one with marks as NULL) and one teacher record.

3. Select: Retrieves students with marks 80 or names starting with ’A’; retrieves
teachers sorted by name.

4. Update: Sets marks to 90 for rollno 102.

5. Delete: Removes student records with NULL marks.

6. Alter: Adds a class column to student.

7. Drop: Deletes the teacher table.


Output (Partial, after executing all commands):
-- SELECT * FROM student WHERE marks >= 80 OR name LIKE ’A%’:
+--------+-------+-------+
| rollno | name | marks |
+--------+-------+-------+
| 101 | Anita | 85 |
| 102 | Ravi | 90 |
+--------+-------+-------+

-- SELECT * FROM teacher ORDER BY name:


+-----+-------+---------+
| tid | name | subject |
+-----+-------+---------+
| 1 | Meena | Math |
+-----+-------+---------+

7
4 Output-Based Questions
1. Question: What is the output of Program 5 after running Program 3? Answer:

+--------+-------+-------+
| rollno | name | marks |
+--------+-------+-------+
| 101 | Anita | 85 |
| 102 | Ravi | 90 |
+--------+-------+-------+

2. Question: What is the output of Program 6 after running Program 3? Answer:

+--------+-------+-------+
| rollno | name | marks |
+--------+-------+-------+
| 102 | Ravi | 90 |
| 101 | Anita | 85 |
| 103 | Suman | 75 |
+--------+-------+-------+

3. Question: What is the output of Program 8 after running Program 4? Answer:

+-----+-------+---------+
| tid | name | subject |
+-----+-------+---------+
| 1 | Meena | Math |
| 2 | Arun | Science |
+-----+-------+---------+

4. Question: After running Programs 3 and 9, what is the output of SELECT * FROM
student? Answer:

+--------+-------+-------+
| rollno | name | marks |
+--------+-------+-------+
| 101 | Anita | 85 |
| 102 | Ravi | 90 |
| 103 | Suman | 80 |
+--------+-------+-------+

5. Question: What is the output of SELECT rollno, name FROM student in Pro-
gram 15 after all commands? Answer:

8
+--------+-------+
| rollno | name |
+--------+-------+
| 101 | Anita |
+--------+-------+

5 Best Practices
• Use clear, meaningful names for tables and columns (e.g., student, rollno).

• Define primary keys to ensure unique records.

• Use WHERE conditions to avoid unintended updates or deletions.

• Use ORDER BY for sorted output when needed.

• Match data types to data (e.g., INTEGER for rollno).

• Test queries on sample data first.

6 Conclusion
This guide covers all relational database topics in the CBSE Class 12 (2025-26) NCERT
syllabus, providing simple SQL programs for creating, querying, updating, and deleting
data, output-based questions, and a final program combining all queries for practical
understanding.

You might also like