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

SQL Full Notes

The document provides comprehensive notes on SQL, covering database basics, table creation, and CRUD operations. It includes examples of select queries, joins, group by with aggregation, and subqueries, as well as constraints for data integrity. Key concepts highlighted are SELECT, WHERE, GROUP BY, JOINS, SUBQUERIES, and CONSTRAINTS.

Uploaded by

Nandish CY
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)
6 views2 pages

SQL Full Notes

The document provides comprehensive notes on SQL, covering database basics, table creation, and CRUD operations. It includes examples of select queries, joins, group by with aggregation, and subqueries, as well as constraints for data integrity. Key concepts highlighted are SELECT, WHERE, GROUP BY, JOINS, SUBQUERIES, and CONSTRAINTS.

Uploaded by

Nandish CY
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 Full Course Notes (Complete)

1. Database Basics

A database is an organized collection of data stored in tables (rows and columns).

2. Table Diagram
Students Table:
+----+--------+-----+
| id | name | age |
+----+--------+-----+
| 1 | John | 20 |
| 2 | Alice | 22 |
+----+--------+-----+

3. Create Table
CREATE TABLE students (
id INT PRIMARY KEY,
name VARCHAR(50),
age INT
);

4. Insert / Update / Delete


INSERT INTO students VALUES (1, 'John', 20);

UPDATE students SET age = 21 WHERE id = 1;

DELETE FROM students WHERE id = 1;

5. Select Queries
SELECT * FROM students;
SELECT name, age FROM students;
SELECT * FROM students WHERE age > 18;

6. Joins Diagram
INNER JOIN:
Students Courses
A ∩ B (common data)

LEFT JOIN:
All A + matched B

RIGHT JOIN:
All B + matched A
7. Join Example
SELECT *
FROM students
INNER JOIN courses
ON [Link] = courses.student_id;

8. Group By & Aggregation


SELECT age, COUNT(*)
FROM students
GROUP BY age
HAVING COUNT(*) > 1;

9. Subquery
SELECT name
FROM students
WHERE age > (SELECT AVG(age) FROM students);

10. Constraints
id INT PRIMARY KEY,
age INT CHECK (age >= 18)

Summary

Core concepts: SELECT, WHERE, GROUP BY, JOINS, SUBQUERIES, CONSTRAINTS.

You might also like