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

SQL Detailed Notes

This document provides detailed notes on SQL and data manipulation, covering key concepts such as SQL commands, constraints, filtering, pattern matching, aggregate functions, joins, subqueries, and transactions. It includes examples for each topic to illustrate their usage. The notes emphasize the importance of SQL in managing data for applications like machine learning.

Uploaded by

aditipmpatil2007
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)
3 views3 pages

SQL Detailed Notes

This document provides detailed notes on SQL and data manipulation, covering key concepts such as SQL commands, constraints, filtering, pattern matching, aggregate functions, joins, subqueries, and transactions. It includes examples for each topic to illustrate their usage. The notes emphasize the importance of SQL in managing data for applications like machine learning.

Uploaded by

aditipmpatil2007
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

UNIT-2: SQL AND DATA MANIPULATION

(DETAILED NOTES)

1. Introduction to SQL

SQL is used to store, retrieve, and manage data in databases. It is very important in AI because it
helps to select and clean data for machine learning.

Example: SELECT * FROM Student WHERE marks > 80;

2. DDL Commands

CREATE: Create table

ALTER: Modify table

DROP: Delete table

Example:

CREATE TABLE Student (id INT, name VARCHAR(50));

3. Constraints

NOT NULL: Cannot be empty

UNIQUE: No duplicate values

PRIMARY KEY: Unique + Not Null

FOREIGN KEY: Connects tables

4. DML Commands

INSERT: Add data

UPDATE: Modify data

DELETE: Remove data

SELECT: View data

Example: INSERT INTO Student VALUES (1, 'Aditi', 20);


5. Filtering

WHERE: Apply condition

ORDER BY: Sorting

GROUP BY: Group data

HAVING: Condition on group

6. Pattern Matching

LIKE: Pattern search (A%)

IN: Multiple values

BETWEEN: Range values

7. Aggregate Functions

COUNT, SUM, AVG, MAX, MIN

Example: SELECT AVG(marks) FROM Student;

8. Joins

INNER JOIN: Matching data

LEFT JOIN: All left + matching right

RIGHT JOIN: All right + matching left

9. Subqueries

Query inside another query

Example: SELECT * FROM Student WHERE marks = (SELECT MAX(marks) FROM Student);

10. Transactions

COMMIT: Save

ROLLBACK: Undo

SAVEPOINT: Temporary save point


Important Queries

SELECT * FROM Student WHERE name LIKE 'A%';

SELECT * FROM Student WHERE age IN (18,20);

SELECT * FROM Student WHERE marks BETWEEN 50 AND 80;

SELECT dept_id, COUNT(*) FROM Student GROUP BY dept_id;

SELECT [Link], d.dept_name FROM Student s INNER JOIN Dept d ON s.dept_id = [Link];

SAVEPOINT sp1;

You might also like