Update docs/tech_docs/sql_notes.md
This commit is contained in:
@@ -1,3 +1,92 @@
|
||||
Creating a more complete SQL reference guide involves encompassing a broad range of SQL syntax, functions, best practices, and advanced concepts. This guide is designed to serve as a comprehensive overview for users at various levels of expertise, offering both a refresher for experienced users and a solid foundation for newcomers.
|
||||
|
||||
# Comprehensive SQL Reference Guide
|
||||
|
||||
## Fundamentals of SQL
|
||||
|
||||
### Data Manipulation Language (DML)
|
||||
- **SELECT**: Retrieves data from a database.
|
||||
- **INSERT**: Inserts new data into a database table.
|
||||
- **UPDATE**: Modifies existing data in a table.
|
||||
- **DELETE**: Removes data from a table.
|
||||
|
||||
### Data Definition Language (DDL)
|
||||
- **CREATE**: Creates new tables, views, or other database objects.
|
||||
- **ALTER**: Modifies the structure of an existing database object.
|
||||
- **DROP**: Deletes tables, views, or other database objects.
|
||||
- **TRUNCATE**: Removes all records from a table, including all spaces allocated for the records.
|
||||
|
||||
### Data Control Language (DCL)
|
||||
- **GRANT**: Gives user's access privileges to database.
|
||||
- **REVOKE**: Removes access privileges from users.
|
||||
|
||||
## Key SQL Statements and Clauses
|
||||
|
||||
### SELECT Statement
|
||||
- Basic syntax: `SELECT column1, column2 FROM table_name WHERE condition GROUP BY column ORDER BY column ASC|DESC;`
|
||||
|
||||
### JOIN Clauses
|
||||
- Types: `INNER JOIN`, `LEFT JOIN` (or `LEFT OUTER JOIN`), `RIGHT JOIN` (or `RIGHT OUTER JOIN`), `FULL JOIN` (or `FULL OUTER JOIN`).
|
||||
- Used to combine rows from two or more tables, based on a related column between them.
|
||||
|
||||
### Subqueries
|
||||
- A query nested inside another query, used for complex queries.
|
||||
- Can be used in `SELECT`, `FROM`, and `WHERE` clauses.
|
||||
|
||||
## Advanced SQL Concepts
|
||||
|
||||
### Indexes
|
||||
- Used to speed up the retrieval of rows from a table.
|
||||
- Important for improving query performance, especially for large datasets.
|
||||
|
||||
### Transactions
|
||||
- A set of SQL operations executed as a single unit of work.
|
||||
- Must be Atomic, Consistent, Isolated, and Durable (ACID).
|
||||
|
||||
### Views
|
||||
- A virtual table based on the result-set of an SQL statement.
|
||||
- Simplifies complex queries, enhances security, and abstracts underlying table structures.
|
||||
|
||||
### Stored Procedures and Functions
|
||||
- **Stored Procedures**: SQL code saved and executed as needed.
|
||||
- **Functions**: Similar to stored procedures but can return a value.
|
||||
|
||||
## SQL Functions
|
||||
|
||||
### String Functions
|
||||
- Examples: `CONCAT`, `LENGTH`, `SUBSTRING`, `UPPER`, `LOWER`.
|
||||
|
||||
### Numeric Functions
|
||||
- Examples: `ABS`, `CEIL`, `FLOOR`, `RAND`, `ROUND`.
|
||||
|
||||
### Date and Time Functions
|
||||
- Examples: `CURRENT_DATE`, `DATE_ADD`, `DATE_DIFF`, `YEAR`, `MONTH`, `DAY`.
|
||||
|
||||
### Aggregate Functions
|
||||
- Examples: `COUNT`, `SUM`, `AVG`, `MIN`, `MAX`.
|
||||
- Often used with the `GROUP BY` clause.
|
||||
|
||||
## Best Practices and Performance Optimization
|
||||
|
||||
### Schema Design
|
||||
- Normalize data to eliminate redundancy and ensure data integrity.
|
||||
- Use appropriate data types for accuracy and efficiency.
|
||||
|
||||
### Query Optimization
|
||||
- Use indexes wisely to improve query performance.
|
||||
- Avoid using `SELECT *`; specify only the needed columns.
|
||||
- Write efficient JOINs and prefer WHERE clauses for filtering.
|
||||
|
||||
### Security Practices
|
||||
- Avoid SQL injection by using parameterized queries.
|
||||
- Implement proper access controls using `GRANT` and `REVOKE`.
|
||||
|
||||
## Conclusion
|
||||
|
||||
This comprehensive SQL reference guide covers the essentials of SQL, from basic queries and DDL operations to more complex concepts like transactions, indexing, and performance optimization. Whether you're a beginner looking to understand the basics or an experienced practitioner seeking to refresh your knowledge on advanced topics, this guide provides a structured overview of SQL's capabilities and best practices.
|
||||
|
||||
---
|
||||
|
||||
Preparing for SQL interviews requires a solid understanding of advanced SQL concepts, queries, and optimizations. This guide is designed to provide a concise overview of typical advanced SQL interview questions, offering quick refreshers on key topics.
|
||||
|
||||
## Advanced SQL Interview Questions Guide
|
||||
|
||||
Reference in New Issue
Block a user