0% found this document useful (0 votes)
24 views2 pages

SQL Class 12 Short Notes for CBSE 2025

SQL (Structured Query Language) is a case-insensitive language used for managing data in relational databases, with commands categorized into DDL, DML, DCL, and TCL. DDL commands create and modify database structures, while DML commands handle data manipulation such as insertion, updating, and retrieval. Key concepts include primary and foreign keys, NULL values, and various aggregate functions for data analysis.

Uploaded by

js0834950
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)
24 views2 pages

SQL Class 12 Short Notes for CBSE 2025

SQL (Structured Query Language) is a case-insensitive language used for managing data in relational databases, with commands categorized into DDL, DML, DCL, and TCL. DDL commands create and modify database structures, while DML commands handle data manipulation such as insertion, updating, and retrieval. Key concepts include primary and foreign keys, NULL values, and various aggregate functions for data analysis.

Uploaded by

js0834950
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

SQL Class 12 – Short Notes (CBSE 2025)

What is SQL?
SQL (Structured Query Language) is used to store, manipulate, and retrieve data in a
relational database. It is case-insensitive but keywords are written in uppercase.

Types of SQL Commands


Type Full Form Purpose
DDL Data Definition Language Defines database structure
DML Data Manipulation Language Manages data within tables
DCL Data Control Language Controls access to data
TCL Transaction Control Language Manages transactions

DDL (Data Definition Language)


Used to create, alter, and delete database objects.

CREATE TABLE
CREATE TABLE Student (RollNo INT PRIMARY KEY, Name VARCHAR(30),
Marks INT, Grade CHAR(1));

ALTER TABLE
ALTER TABLE Student ADD Age INT;
ALTER TABLE Student MODIFY Name VARCHAR(50);
ALTER TABLE Student DROP COLUMN Grade;

DROP TABLE
DROP TABLE Student;

RENAME TABLE
RENAME TABLE Student TO Class12;

TRUNCATE TABLE
TRUNCATE TABLE Student;

DML (Data Manipulation Language)


Used to add, update, delete, or retrieve data.

INSERT
INSERT INTO Student VALUES (101, 'Aman', 89, 'A');
INSERT INTO Student (RollNo, Name) VALUES (102, 'Riya');

UPDATE
UPDATE Student SET Marks = 95 WHERE RollNo = 101;

DELETE
DELETE FROM Student WHERE RollNo = 102;

SELECT
SELECT * FROM Student;
SELECT Name, Marks FROM Student WHERE Marks > 80;

Important Clauses
WHERE – filters records.
ORDER BY – sorts data.
GROUP BY – groups rows having same values.
HAVING – applies condition on grouped data.

Aggregate Functions
COUNT() – returns number of rows.
SUM() – returns total sum.
AVG() – returns average value.
MAX() – returns maximum value.
MIN() – returns minimum value.

Additional Topics
Primary Key – uniquely identifies a record.
Foreign Key – links two tables.
NULL – represents missing or unknown data.
DISTINCT – removes duplicate rows in result.
BETWEEN, IN, LIKE – used for conditional selection.

Common questions

Powered by AI

Handling NULL values in SQL is crucial because NULL represents unknown or missing data, affecting data manipulation and logical operations. Operations involving NULL often result in unknown outcomes unless specifically handled using functions like COALESCE or IS NULL checks. This impacts how queries return results, especially in aggregate functions or conditions, and necessitates careful design to manage NULL-related logic and prevent inaccurate data processing.

The HAVING clause is important because it applies conditions to aggregated data, allowing users to filter groups as opposed to individual rows. Unlike the WHERE clause, which filters rows before any aggregation takes place, HAVING filters after data has been grouped and aggregated. This is essential for performing post-group filtering and refining the result set based on aggregate conditions.

DML commands contribute significantly to the dynamic nature of working with data in a relational database by allowing users to directly insert, update, delete, and retrieve data from tables. This provides flexibility in data handling, as users can modify records as needs change and retrieve specific data sets for analysis, making the management of a database an ongoing, adaptive process .

ORDER BY and GROUP BY serve different functions within an SQL query. ORDER BY is used to sort the result set of a query by one or more columns, either in ascending or descending order, helping organize the data systematically. Conversely, GROUP BY is used to aggregate data across multiple records and group the results by one or more columns, often used with aggregate functions like COUNT, SUM, AVG, etc., to perform operations on grouped data.

A foreign key facilitates relationships between tables by linking a column (or a set of columns) in one table to a primary key in another table, thereby establishing a referential integrity constraint. This relationship allows for the connection of related data across tables, enabling complex queries and operations that involve data from multiple tables while ensuring that data remains consistent and logically connected.

A primary key is crucial in a database table because it uniquely identifies each record, ensuring that no duplicate rows exist and that each entry can be distinguished from others. This is vital for data integrity, as it maintains consistency and reliability in the database, allowing for accurate updates and data retrieval while preventing data anomalies.

The DISTINCT keyword plays a role in ensuring that duplicate rows are removed from a result set, providing a cleaner and more accurate representation of data. It would be necessary to use DISTINCT in a scenario such as reporting unique transaction identifiers from a sales table to prevent counting the same sale multiple times, or listing unique customer email addresses to avoid sending duplicate communications.

Aggregate functions in SQL play the role of performing calculations on multiple rows of data to return a single value. They are particularly useful in scenarios where summaries or collective values are needed—for instance, to calculate total revenue (SUM), average scores (AVG), highest sales figures (MAX), lowest temperatures recorded (MIN), or the number of participants in an event (COUNT). Such functions facilitate efficient analysis and reporting of grouped data.

The WHERE clause enhances the flexibility of data retrieval by allowing specific conditions to be set on the data being queried. It enables users to filter records based on criteria, ensuring that only the required data is fetched. This facilitates effective data analysis, as queries can be tailored to meet precise needs without retrieving unnecessary data, thus increasing efficiency when working with large datasets.

DDL commands in SQL are significant because they define the structure of a database, including the creation, alteration, and deletion of database objects. They differ from other SQL command types in their primary focus on the schema rather than managing data directly or controlling transactions. DML is used specifically for data manipulation within tables, DCL handles access permissions and security, and TCL is used to manage transactions within the database, ensuring consistency.

You might also like