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

Complete SQL Notes: Basics to Advanced

The document provides comprehensive SQL notes covering basic to advanced concepts, including SQL operations, data types, and various functions. It details DDL, DML, DQL, joins, subqueries, views, indexes, transactions, and normalization. Additionally, it highlights important concepts such as constraints, aggregate functions, and set operators.

Uploaded by

katikaveni103
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)
51 views2 pages

Complete SQL Notes: Basics to Advanced

The document provides comprehensive SQL notes covering basic to advanced concepts, including SQL operations, data types, and various functions. It details DDL, DML, DQL, joins, subqueries, views, indexes, transactions, and normalization. Additionally, it highlights important concepts such as constraints, aggregate functions, and set operators.

Uploaded by

katikaveni103
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

Complete SQL Notes - Basic to Advanced

SQL Theory and Concepts

1. SQL Basics
- SQL (Structured Query Language) is used to interact with relational databases.
- Common operations: CREATE, INSERT, SELECT, UPDATE, DELETE.

2. SQL Data Types


- INT, VARCHAR(n), CHAR(n), DATE, TIME, FLOAT, BOOLEAN, etc.

3. DDL (Data Definition Language)


- CREATE TABLE table_name (...)
- ALTER TABLE table_name ADD|MODIFY|DROP column_name
- DROP TABLE table_name

4. DML (Data Manipulation Language)


- INSERT INTO table_name (columns) VALUES (...)
- UPDATE table_name SET column=value WHERE condition
- DELETE FROM table_name WHERE condition

5. DQL (Data Query Language)


- SELECT * FROM table_name
- SELECT col1, col2 FROM table WHERE condition

6. Aggregate Functions
- COUNT(), SUM(), AVG(), MIN(), MAX()

7. String Functions
- CONCAT(), LENGTH(), LOWER(), UPPER(), SUBSTRING(), TRIM()

8. Date/Time Functions
- NOW(), CURDATE(), DATEDIFF(), DATE_ADD(), DAY(), MONTH(), YEAR()

9. Numeric Functions
- ROUND(), CEIL(), FLOOR(), ABS(), MOD()

10. Conversion Functions


- CAST(expr AS type), CONVERT(expr, type)

11. Logical Functions


- IF(), CASE WHEN THEN ELSE END

12. Constraints
- PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, CHECK, DEFAULT

13. Joins
- INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN, SELF JOIN

14. Subqueries
- Scalar, Correlated, Nested, EXISTS/IN
Complete SQL Notes - Basic to Advanced

15. Views
- CREATE VIEW view_name AS SELECT ...
- DROP VIEW view_name

16. Indexes
- CREATE INDEX idx_name ON table(col)
- DROP INDEX idx_name ON table

17. Transactions
- START TRANSACTION
- COMMIT
- ROLLBACK
- SAVEPOINT name

18. Set Operators


- UNION, UNION ALL, INTERSECT, EXCEPT

19. Normalization
- 1NF, 2NF, 3NF: removing redundancy and improving data integrity.

20. Other Important Concepts


- AUTO_INCREMENT, DEFAULT values, Aliases (AS), ORDER BY, GROUP BY, HAVING

Common questions

Powered by AI

Indexes significantly enhance query performance by allowing faster data retrieval through structured data pointers. They are crucial for large datasets, particularly in search and retrieval operations. However, indexes come with downsides: increased storage requirements and slower data manipulation (INSERT, UPDATE, DELETE) due to index maintenance. Appropriate indexing balances performance gains against these costs .

Normalization involves organizing database tables to minimize redundancy and dependency by ensuring that each table serves a specific purpose and data is uniquely identified. It progresses through normal forms (1NF, 2NF, 3NF) that incrementally remove duplication and ensure data integrity. Normalization improves data consistency and reduces storage needs, making database operations more efficient and reliable .

Set operators in SQL, including UNION, UNION ALL, INTERSECT, and EXCEPT, allow for the combination and comparison of query results. UNION and UNION ALL combine results from multiple queries, with UNION eliminating duplicates. INTERSECT returns common rows across queries, while EXCEPT finds rows in one query but not another. These operators enable complex data analysis but require careful handling, especially regarding operand data type compatibility and ordering .

Subqueries in SQL allow more complex queries by embedding a query within another. Scalar subqueries return a single value, often used in conditions or assignments. Correlated subqueries run for each row processed by the outer query, allowing dynamic comparison. Nested subqueries involve multi-level querying, where one query serves as data source for another. Subqueries increase flexibility and depth in data retrieval strategies .

Transactions provide atomicity, consistency, isolation, and durability (ACID) in SQL databases, ensuring reliable data operations, even in failures. Advantages include guaranteed data consistency and fault tolerance. Disadvantages may include complexity and performance overhead in managing transactions, especially in high-concurrency systems. Proper use prevents partial updates and maintains application integrity .

INNER JOIN returns only the rows with matching values in both tables. In contrast, OUTER JOIN includes unmatched rows based on the type: LEFT OUTER JOIN returns all rows from the left table and matched rows from the right table; RIGHT OUTER JOIN does the opposite. FULL OUTER JOIN includes rows from both tables whether or not there are matches. INNER JOIN is more restrictive, showing only connected data, while OUTER JOIN provides a more comprehensive overview by including optional data points .

SQL data types define the kind of data stored in each table column, influencing how data is stored, processed, and retrieved. Proper data typing ensures efficient storage and enforces data integrity by preventing invalid data entries. Common types include INT for integers, VARCHAR for variable-length text, and DATE for dates. Using appropriate data types maximizes performance and enforces constraints on data validity .

Aggregate functions like COUNT(), SUM(), AVG(), MIN(), and MAX() provide summarized data from a set of values, allowing for comprehensive analysis of data patterns and trends. They are commonly used in scenarios requiring numerical data aggregation, such as calculating total sales, finding average salaries, determining minimum or maximum values in a dataset, and counting occurrences of a specific event .

SQL constraints enforce rules on data in tables to ensure accuracy and reliability. Types include PRIMARY KEY, uniquely identifying records; FOREIGN KEY, linking tables to maintain referential integrity; UNIQUE, enforcing uniqueness on column values; NOT NULL, disallowing empty values; CHECK, ensuring column data meets specified conditions; and DEFAULT, providing default values when none are supplied. These constraints protect data quality and enforce business rules .

Views are virtual tables in SQL that enhance query performance by simplifying complex queries and reusing SQL code, reducing retrieval time. They also contribute to security by providing specific data access, hiding complex queries, and controlling user access to data subsets. However, views are not suited for updating data unless they are simple enough for direct correspondence to underlying tables .

You might also like