chore: sync content to repo

This commit is contained in:
kamranahmedse
2026-03-06 15:05:37 +00:00
committed by github-actions[bot]
parent 2e45440cc6
commit d08b0e8e1b
110 changed files with 194 additions and 358 deletions

View File

@@ -2,7 +2,7 @@
The `ABS()` function in SQL returns the absolute value of a given numeric expression, meaning it converts any negative number to its positive equivalent while leaving positive numbers unchanged. This function is useful when you need to ensure that the result of a calculation or a value stored in a database column is non-negative, such as when calculating distances, differences, or other metrics where only positive values make sense. For example, `SELECT ABS(-5)` would return `5`.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@How to compute an absolute value in SQL](https://www.airops.com/sql-guide/how-to-compute-an-absolute-value-in-sql)
- [@article@ABS](https://www.w3schools.com/sql/func_sqlserver_abs.asp)

View File

@@ -6,4 +6,4 @@ Visit the following resources to learn more:
- [@article@What is ACID Compliant Database?](https://retool.com/blog/whats-an-acid-compliant-database/)
- [@article@What is ACID Compliance?: Atomicity, Consistency, Isolation](https://fauna.com/blog/what-is-acid-compliance-atomicity-consistency-isolation)
- [@video@ACID Explained: Atomic, Consistent, Isolated & Durable](https://www.youtube.com/watch?v=yaQ5YMWkxq4)
- [@video@ACID Explained: Atomic, Consistent, Isolated & Durable](https://www.youtube.com/watch?v=yaQ5YMWkxq4)

View File

@@ -1,8 +1,3 @@
# Advanced SQL Functions
# Advanced Functions
Advanced SQL functions enable more sophisticated data manipulation and analysis within databases, offering powerful tools for complex queries. Key areas include:
- **String Functions**: Manipulate text data using functions like `CONCAT`, `SUBSTRING`, and `REPLACE` to combine, extract, or modify strings.
- **Date & Time**: Manage temporal data with functions like `DATEADD`, `DATEDIFF`, and `FORMAT`, allowing for calculations and formatting of dates and times.
- **Numeric Functions**: Perform advanced calculations using functions such as `ROUND`, `FLOOR`, and `CEIL`, providing precision in numerical data processing.
- **Conditional**: Implement logic within queries using functions like `CASE`, `COALESCE`, and `NULLIF` to control data flow and handle conditional scenarios.
Advanced functions in SQL go beyond the basic operations like selecting and filtering data. These functions allow you to perform complex calculations, manipulate strings, work with dates, and analyze data in more sophisticated ways. They help you derive insights, transform data, and create more meaningful reports from your database.

View File

@@ -1,10 +1,3 @@
# Aggregate Queries
Aggregate queries in SQL are used to perform calculations on multiple rows of data, returning a single summary value or grouped results. These queries typically involve the use of aggregate functions, such as:
• COUNT(): Returns the number of rows that match a specific condition.
• SUM(): Calculates the total sum of a numeric column.
• AVG(): Computes the average value of a numeric column.
• MIN() and MAX(): Find the smallest and largest values in a column, respectively.
• GROUP BY: Used to group rows that share a common value in specified columns, allowing aggregate functions to be applied to each group.
• HAVING: Filters the results of a GROUP BY clause based on a specified condition, similar to WHERE but for groups.
Aggregate queries in SQL are used to calculate summary values from multiple rows of a table, reducing the data to a single row based on a specific calculation. These calculations provide insights like totals, averages, and counts. Commonly used aggregate functions include `COUNT()` to count rows, `SUM()` to add values, `AVG()` to calculate the average, `MIN()` to find the minimum value, and `MAX()` to find the maximum value within a group of rows.

View File

@@ -2,7 +2,7 @@
The `ALTER TABLE` statement in SQL is used to modify the structure of an existing table. This includes adding, dropping, or modifying columns, changing the data type of a column, setting default values, and adding or dropping primary or foreign keys.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@ALTER TABLE Statement](https://www.techonthenet.com/sql/tables/alter_table.php)
- [@article@ALTER TABLE - PostgreSQL](https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-alter-table/)

View File

@@ -2,7 +2,7 @@
The `AVG()` function in SQL is an aggregate function that calculates the average value of a numeric column. It returns the sum of all the values in the column, divided by the count of those values.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@AVG](https://www.sqlshack.com/sql-avg-function-introduction-and-examples/)
- [@article@SQL AVG() Function](https://www.w3schools.com/sql/sql_avg.asp)

View File

@@ -2,7 +2,7 @@
Basic SQL syntax consists of straightforward commands that allow users to interact with a relational database. The core commands include `SELECT` for querying data, `INSERT INTO` for adding new records, `UPDATE` for modifying existing data, and `DELETE` for removing records. Queries can be filtered using `WHERE`, sorted with `ORDER BY`, and data from multiple tables can be combined using `JOIN`. These commands form the foundation of SQL, enabling efficient data manipulation and retrieval within a database.
Learn more about SQL from the following resources:
Visit the following resources to learn more:
- [@article@SQL Tutorial - Mode](https://mode.com/sql-tutorial/)
- [@article@SQL Tutorial](https://www.sqltutorial.org/)
- [@article@SQL Tutorial](https://www.sqltutorial.org/)

View File

@@ -2,7 +2,7 @@
`BEGIN` is used in SQL to start a transaction, which is a sequence of one or more SQL operations that are executed as a single unit. A transaction ensures that all operations within it are completed successfully before any changes are committed to the database. If any part of the transaction fails, the `ROLLBACK` command can be used to undo all changes made during the transaction, maintaining the integrity of the database. Once all operations are successfully completed, the `COMMIT` command is used to save the changes. Transactions are crucial for maintaining data consistency and handling errors effectively.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@BEGIN...END Statement](https://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc00801.1510/html/iqrefso/BABFBJAB.htm)
- [@article@SQL 'BEGIN' & 'END' Statements](https://reintech.io/blog/understanding-sql-begin-end-statements-guide)

View File

@@ -2,6 +2,6 @@
The CASE statement in SQL is used to create conditional logic within a query, allowing you to perform different actions based on specific conditions. It operates like an if-else statement, returning different values depending on the outcome of each condition. The syntax typically involves specifying one or more WHEN conditions, followed by the result for each condition, and an optional ELSE clause for a default outcome if none of the conditions are met.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL CASE - Intermediate SQL](https://mode.com/sql-tutorial/sql-case)

View File

@@ -2,6 +2,6 @@
The `CEILING()` function in SQL returns the smallest integer greater than or equal to a given numeric value. It's useful when you need to round up a number to the nearest whole number, regardless of whether the number is already an integer or a decimal. For example, `CEILING(4.2)` would return `5`, and `CEILING(-4.7)` would return `-4`. This function is commonly used in scenarios where rounding up is necessary, such as calculating the number of pages needed to display a certain number of items when each page has a fixed capacity.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL CEILING](https://www.w3schools.com/sql/func_sqlserver_ceiling.asp)

View File

@@ -2,6 +2,6 @@
A `CHECK` constraint in SQL is used to enforce data integrity by specifying a condition that must be true for each row in a table. It allows you to define custom rules or restrictions on the values that can be inserted or updated in one or more columns. `CHECK` constraints help maintain data quality by preventing invalid or inconsistent data from being added to the database, ensuring that only data meeting specified criteria is accepted.
Learn more from the following resources:
Visit the following resources to learn more:
- [@video@CHECK Constraint](https://www.youtube.com/watch?v=EeG2boJCXbc)
- [@video@CHECK Constraint](https://www.youtube.com/watch?v=EeG2boJCXbc)

View File

@@ -2,7 +2,7 @@
`COALESCE` is an SQL function that returns the first non-null value in a list of expressions. It's commonly used to handle null values or provide default values in queries. `COALESCE` evaluates its arguments in order and returns the first non-null result, making it useful for data cleaning, report generation, and simplifying complex conditional logic in SQL statements.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@How to use the COALESCE function in SQL](https://learnsql.com/blog/coalesce-function-sql/)
- [@article@COALESCE - PostgreSQL](https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-coalesce/)

View File

@@ -1,7 +1,7 @@
# Column
In SQL, columns are used to categorize the data in a table. A column serves as a structure that stores a specific type of data (ints, str, bool, etc.) in a table. Each column in a table is designed with a type, which configures the data that it can hold. Using the right column types and size can help to maintain data integrity and optimize performance.
In SQL, columns are used to categorize the data in a table. A column serves as a structure that stores a specific type of data (ints, str, bool, etc.) in a table. Each column in a table is designed with a type, which configures the data that it can hold. Using the right column types and size can help to maintain data integrity and optimize performance.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@Column Types - PostgreSQL](https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-data-types/)

View File

@@ -1,9 +1,7 @@
# COMMIT
The SQL COMMIT command is used to save all the modifications made by the current transaction to the database. A COMMIT command ends the current transaction and makes permanent all changes performed in the transaction. It is a way of ending your transaction and saving your changes to the database.
COMMIT is an SQL command that saves all changes made during a transaction to the database. Until a COMMIT command is issued, all modifications within a transaction are only temporary and visible to the current session. Once COMMIT is executed, the changes become permanent and visible to other users and sessions. This ensures data consistency and durability.
After the SQL COMMIT statement is executed, it can not be rolled back, which means you can't undo the operations. COMMIT command is used when the user is satisfied with the changes made in the transaction, and these changes can now be made permanent in the database.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL COMMIT and ROLLBACK](https://www.digitalocean.com/community/tutorials/sql-commit-sql-rollback)

View File

@@ -2,7 +2,7 @@
Common Table Expressions (CTEs) in SQL are named temporary result sets that exist within the scope of a single `SELECT`, `INSERT`, `UPDATE`, `DELETE`, or `MERGE` statement. Defined using the `WITH` clause, CTEs act like virtual tables that can be referenced multiple times within a query. They improve query readability, simplify complex queries by breaking them into manageable parts, and allow for recursive queries. CTEs are particularly useful for hierarchical or graph-like data structures and can enhance query performance in some database systems.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@Common Table Expressions (CTEs)](https://hightouch.com/sql-dictionary/sql-common-table-expression-cte)
- [@article@What is a Common Table Expression?](https://learnsql.com/blog/what-is-common-table-expression/)
- [@article@What is a Common Table Expression?](https://learnsql.com/blog/what-is-common-table-expression/)

View File

@@ -2,6 +2,6 @@
`CONCAT` is an SQL function used to combine two or more strings into a single string. It takes multiple input strings as arguments and returns a new string that is the concatenation of all the input strings in the order they were provided. `CONCAT` is commonly used in `SELECT` statements to merge data from multiple columns, create custom output formats, or generate dynamic SQL statements.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@An overview of the CONCAT function in SQL](https://www.sqlshack.com/an-overview-of-the-concat-function-in-sql-with-examples/)
- [@article@An overview of the CONCAT function in SQL](https://www.sqlshack.com/an-overview-of-the-concat-function-in-sql-with-examples/)

View File

@@ -2,7 +2,7 @@
In SQL, a correlated subquery is a subquery that uses values from the outer query in its `WHERE` clause. The correlated subquery is evaluated once for each row processed by the outer query. It exists because it depends on the outer query and it cannot execute independently of the outer query because the subquery is correlated with the outer query as it uses its column in its `WHERE` clause.
Learn more from the following resources:
Visit the following resources to learn more:
- [@official@Correlated Subqueries](https://dev.mysql.com/doc/refman/8.4/en/correlated-subqueries.html)
- [@video@Intro To Subqueries](https://www.youtube.com/watch?v=TUxadt94L0M)

View File

@@ -2,6 +2,6 @@
`COUNT` is an SQL aggregate function that returns the number of rows that match the specified criteria. It can be used to count all rows in a table, non-null values in a specific column, or rows that meet certain conditions when combined with a `WHERE` clause. `COUNT` is often used in data analysis, reporting, and performance optimization queries to determine the size of datasets or the frequency of particular values.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@COUNT SQL Function](https://www.datacamp.com/tutorial/count-sql-function)

View File

@@ -2,7 +2,7 @@
`CREATE TABLE` is an SQL statement used to define and create a new table in a database. It specifies the table name, column names, data types, and optional constraints such as primary keys, foreign keys, and default values. This statement establishes the structure of the table, defining how data will be stored and organized within it. `CREATE TABLE` is a fundamental command in database management, essential for setting up the schema of a database and preparing it to store data.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@CREATE TABLE](https://www.tutorialspoint.com/sql/sql-create-table.htm)
- [@article@SQL CREATE TABLE](https://www.programiz.com/sql/create-table)

View File

@@ -2,7 +2,7 @@
Creating views in SQL involves using the `CREATE VIEW` statement to define a virtual table based on the result of a `SELECT` query. Views don't store data themselves but provide a way to present data from one or more tables in a specific format. They can simplify complex queries, enhance data security by restricting access to underlying tables, and provide a consistent interface for querying frequently used data combinations. Views can be queried like regular tables and are often used to encapsulate business logic or present data in a more user-friendly manner.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@How to create a view in SQL](https://www.sqlshack.com/how-to-create-a-view-in-sql-server/)
- [@video@SQL Views in 4 minutes](https://www.youtube.com/watch?v=vLLkNI-vkV8)

View File

@@ -1,9 +1,7 @@
# Cross Join
The cross join in SQL is used to combine every row of the first table with every row of the second table. It's also known as the Cartesian product of the two tables. The most important aspect of performing a cross join is that it does not require any condition to join.
A Cross Join produces a result set that is the number of rows in the first table multiplied by the number of rows in the second table. If a WHERE clause is used in conjunction with a CROSS JOIN, it functions like an INNER JOIN. However, using an INNER JOIN is generally preferred to using a CROSS JOIN with a WHERE clause for readability and performance reasons. It essentially creates all possible combinations of rows from the tables involved.
The issue with cross join is it returns the Cartesian product of the two tables, which can result in large numbers of rows and heavy resource usage. It's hence critical to use them wisely and only when necessary.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL CROSS JOIN With Examples](https://www.sqlshack.com/sql-cross-join-with-examples/)

View File

@@ -2,6 +2,6 @@
Data constraints in SQL are rules applied to columns or tables to enforce data integrity and consistency. They include primary key, foreign key, unique, check, and not null constraints. These constraints define limitations on the data that can be inserted, updated, or deleted in a database, ensuring that the data meets specific criteria and maintains relationships between tables. By implementing data constraints, database designers can prevent invalid data entry, maintain referential integrity, and enforce business rules directly at the database level.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL Constraints](https://www.programiz.com/sql/constraints)

View File

@@ -2,7 +2,7 @@
Data Definition Language (DDL) is a subset of SQL used to define and manage the structure of database objects. DDL commands include `CREATE`, `ALTER`, `DROP`, and `TRUNCATE`, which are used to create, modify, delete, and empty database structures such as tables, indexes, views, and schemas. These commands allow database administrators and developers to define the database schema, set up relationships between tables, and manage the overall structure of the database. DDL statements typically result in immediate changes to the database structure and can affect existing data.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@Data Definition Language (DDL)](https://docs.getdbt.com/terms/ddl)
- [@article@The Definitive Guide on Data Definition Language](https://www.dbvis.com/thetable/sql-ddl-the-definitive-guide-on-data-definition-language/)

View File

@@ -1,5 +1,3 @@
# Data Integrity and Security
# Data Integrity & Security
Data integrity and security in SQL encompass measures and techniques to ensure data accuracy, consistency, and protection within a database. This includes implementing constraints (like primary keys and foreign keys), using transactions to maintain data consistency, setting up user authentication and authorization, encrypting sensitive data, and regularly backing up the database.
SQL provides various tools and commands to enforce data integrity rules, control access to data, and protect against unauthorized access or data corruption, ensuring the reliability and confidentiality of stored information.
Data integrity ensures that the information stored in a database is accurate, consistent, and reliable over its entire lifecycle. Data security involves protecting the database from unauthorized access, modification, or deletion. These two concepts are essential for maintaining the trust and value of any database system, safeguarding against corruption, breaches, and ensuring data is used appropriately.

View File

@@ -1,10 +1,8 @@
# Data Integrity Constraints
SQL constraints are used to specify rules for the data in a table. They ensure the accuracy and reliability of the data within the table. If there is any violation between the constraint and the action, the action is aborted by the constraint.
Data integrity constraints are rules you set up in a database to make sure the data is accurate and reliable. These rules prevent bad data from being entered into tables. Think of them as checks and balances that maintain the quality of your information by enforcing specific criteria like uniqueness, valid ranges, or required values.
Constraints are classified into two types: column level and table level. Column level constraints apply to individual columns whereas table level constraints apply to the entire table. Each constraint has its own purpose and usage, utilizing them effectively helps maintain the accuracy and integrity of the data.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@Integrity Constraints in SQL: A Guide With Examples](https://www.datacamp.com/tutorial/integrity-constraints-sql)
- [@article@Integrity Constraints](https://dataheadhunters.com/academy/integrity-constraints-ensuring-accuracy-and-consistency-in-your-data/)

View File

@@ -6,4 +6,4 @@ Visit the following resources to learn more:
- [@article@What is DML?](https://satoricyber.com/glossary/dml-data-manipulation-language)
- [@article@What is DML?(Wiki)](https://en.wikipedia.org/wiki/Data_manipulation_language)
- [@article@Difference Between DMS & DML](https://appmaster.io/blog/difference-between-ddl-and-dml)
- [@article@Difference Between DMS & DML](https://appmaster.io/blog/difference-between-ddl-and-dml)

View File

@@ -2,7 +2,7 @@
SQL data types define the kind of values that can be stored in a column and determine how the data is stored, processed, and retrieved. Common data types include numeric types (`INTEGER`, `DECIMAL`), character types (`CHAR`, `VARCHAR`), date and time types (`DATE`, `TIMESTAMP`), binary types (`BLOB`), and boolean types. Each database management system may have its own specific set of data types with slight variations. Choosing the appropriate data type for each column is crucial for optimizing storage, ensuring data integrity, and improving query performance.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL Data Types](https://www.digitalocean.com/community/tutorials/sql-data-types)
- [@video@MySQL 101 - Data Types](https://www.youtube.com/watch?v=vAiBa69YCnk)

View File

@@ -2,6 +2,6 @@
The DATE data type in SQL is used to store calendar dates (typically in the format YYYY-MM-DD). It represents a specific day without any time information. DATE columns are commonly used for storing birthdates, event dates, or any other data that requires only day-level precision. SQL provides various functions to manipulate and format DATE values, allowing for date arithmetic, extraction of date components, and comparison between dates. The exact range of valid dates may vary depending on the specific database management system being used.
Learn more from the following resources:
Visit the following resources to learn more:
- [@video@Working with Dates](https://www.youtube.com/watch?v=XyZ9HwXoR7o)

View File

@@ -2,7 +2,7 @@
`DATEADD` is an SQL function used to add or subtract a specified time interval to a date or datetime value. It typically takes three arguments: the interval type (e.g., day, month, year), the number of intervals to add or subtract, and the date to modify. This function is useful for date calculations, such as finding future or past dates, calculating durations, or generating date ranges. The exact syntax and name of this function may vary slightly between different database management systems (e.g., `DATEADD` in SQL Server, `DATE_ADD` in MySQL).
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@DATEADD](https://www.mssqltips.com/sqlservertutorial/9380/sql-dateadd-function/)
- [@video@DATEADD Function](https://www.youtube.com/watch?v=DYCWOzzOycU)

View File

@@ -2,6 +2,6 @@
`DATEPART` is a useful function in SQL that allows you to extract a specific part of a date or time field. You can use it to get the year, quarter, month, day of the year, day, week, weekday, hour, minute, second, or millisecond from any date or time expression.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL DATEPART](https://hightouch.com/sql-dictionary/sql-datepart)

View File

@@ -1,47 +1,7 @@
# Database Security Best Practices
# DB Security Best Practices
Database security is key in ensuring sensitive information is kept intact and isn't exposed to a malicious or accidental breach. Here are some best practices related to SQL security:
Database security best practices are a collection of methods used to protect sensitive data from unauthorized access, modification, or deletion. They involve implementing access controls based on the least privilege principle, routinely updating systems, using strong passwords, limiting remote access, avoiding the admin account for everyday tasks, encrypting communication, performing regular backups, monitoring and auditing database operations, performing vulnerability scanning, and guarding against SQL injection attacks by using parameterized queries or prepared statements.
## 1. Least Privilege Principle
This principle states that a user should have the minimum levels of access necessary and nothing more. For large systems, this could require a good deal of planning.
## 2. Regular Updates
Always keep SQL Server patched and updated to gain the benefit of the most recent security updates.
## 3. Complex and Secure Passwords
Passwords should be complex and frequently changed. Alongside the use of `GRANT` and `REVOKE`, this is the front line of defense.
## 4. Limiting Remote Access
If remote connections to the SQL server are not necessary, it is best to disable it.
## 5. Avoid Using SQL Server Admin Account
You should avoid using the SQL Server admin account for regular database operations to limit security risk.
## 6. Encrypt Communication
To protect against data sniffing, all communication between SQL Server and applications should be encrypted.
## 7. Database Backups
Regular database backups are crucial for data integrity if there happens to be a data loss.
## 8. Monitoring and Auditing
Regularly monitor and audit your database operations to keep track of who does what in your database.
## 9. Regular Vulnerability Scanning
Use a vulnerability scanner to assess the security posture of your SQL.
## 10. SQL Injection
SQL injection can be reduced by using parameterized queries or prepared statements.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@What is database security?](https://azure.microsoft.com/en-us/resources/cloud-computing-dictionary/what-is-database-security)

View File

@@ -1,7 +1,7 @@
# Delete
# DELETE Statement
DELETE is an SQL statement used to remove one or more rows from a table. It allows you to specify which rows to delete using a WHERE clause, or delete all rows if no condition is provided. DELETE is part of the Data Manipulation Language (DML) and is used for data maintenance, removing outdated or incorrect information, or implementing business logic that requires data removal. When used without a WHERE clause, it empties the entire table while preserving its structure, unlike the TRUNCATE command.
The DELETE statement removes rows from a table. You specify which table to remove data from and can use a WHERE clause to filter which rows should be deleted based on specific conditions. If no WHERE clause is provided, all rows in the table will be deleted.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@DELETE](https://www.w3schools.com/sql/sql_delete.asp)

View File

@@ -1,7 +1,7 @@
# DELETE
# DELETE Statement in SQL
DELETE is an SQL statement used to remove one or more rows from a table. It allows you to specify which rows to delete using a WHERE clause, or delete all rows if no condition is provided. DELETE is part of the Data Manipulation Language (DML) and is used for data maintenance, removing outdated or incorrect information, or implementing business logic that requires data removal. When used without a WHERE clause, it empties the entire table while preserving its structure, unlike the TRUNCATE command.
The `DELETE` statement in SQL removes existing records from a table. You specify which table to affect and can optionally include a `WHERE` clause to specify conditions for which rows should be deleted. If no `WHERE` clause is provided, all rows in the table will be deleted. It modifies the data within the database by removing entire rows based on the given criteria.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@DELETE](https://www.w3schools.com/sql/sql_delete.asp)

View File

@@ -1,10 +1,8 @@
# dense_rank
`DENSE_RANK` is a window function in SQL that assigns a rank to each row within a window partition, with no gaps in the ranking numbers.
`dense_rank` is a window function that assigns a rank to each row within a partition of a result set, based on the order of rows. Unlike the `rank` function, `dense_rank` assigns consecutive ranks without gaps, even when there are ties in the ordering criteria. This means that if two or more rows have the same value for the ordering column(s), they will receive the same rank, and the next rank assigned will be the next consecutive integer, without skipping any numbers.
Unlike the `RANK` function, `DENSE_RANK` does not skip any rank (positions in the order). If you have, for example, 1st, 2nd, and 2nd, the next rank listed would be 3rd when using `DENSE_RANK`, whereas it would be 4th using the `RANK` function. The `DENSE_RANK` function operates on a set of rows, called a window, and in that window, values are compared to each other.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL DENSE_RANK](https://www.sqltutorial.org/sql-window-functions/sql-dense_rank/)
- [@article@Breaking Down DENSE_RANK](https://www.kdnuggets.com/breaking-down-denserank-a-step-by-step-guide-for-sql-enthusiasts)

View File

@@ -1,9 +1,7 @@
# Drop Table
The `DROP TABLE` statement is a Data Definition Language (DDL) operation that is used to **completely remove** a table from the database. This operation deletes the table structure along with **all the data in** it, effectively removing the table from the database system.
The `DROP TABLE` statement removes a table and its data entirely from a database. It's a permanent operation; once a table is dropped, its structure and all the data it contained are lost unless you have a backup. This command should be used with caution, as it can have significant consequences for your database.
When you execute the `DROP TABLE` statement, it eliminates both the table and its data, as well as any associated indexes, constraints, and triggers. Unlike the `TRUNCATE TABLE` statement, which only removes data but keeps the table structure, `DROP TABLE` removes everything associated with the table.
Visit the following resources to learn more:
Learn more from the following resources:
- [@article@Drop a Table](https://www.coginiti.co/tutorials/beginner/drop-a-table/)
- [@article@Drop a Table](https://www.coginiti.co/tutorials/beginner/drop-a-table/)

View File

@@ -2,7 +2,7 @@
Dropping views in SQL involves using the `DROP VIEW` statement to remove an existing view from the database. This operation permanently deletes the view definition, but it doesn't affect the underlying tables from which the view was created. Dropping a view is typically done when the view is no longer needed, needs to be replaced with a different definition, or as part of database maintenance. It's important to note that dropping a view can impact other database objects or applications that depend on it, so caution should be exercised when performing this operation.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@DROP VIEW](https://study.com/academy/lesson/sql-drop-view-tutorial-overview.html)
- [@article@DROP or DELETE a View](https://www.tutorialspoint.com/sql/sql-drop-view.htm)

View File

@@ -1,10 +1,8 @@
# Dynamic SQL
Dynamic SQL is a programming method that allows you to build SQL statements dynamically at runtime. It allows you to create more flexible and adaptable applications because you can manipulate the SQL statements on the fly, in response to inputs or changing conditions.
Dynamic SQL refers to the ability to construct and execute SQL statements programmatically during runtime. Instead of writing static SQL queries directly into your code, you can build SQL strings based on varying conditions, user inputs, or other dynamic factors. This allows for more flexible and adaptable database interactions, enabling you to generate queries tailored to specific situations that cannot be known in advance.
Consider an application where a user can choose multiple search conditions from a range of choices. You might not know how many conditions the user will choose, or what they'll be until runtime. With static SQL, you would have to include a large number of potential search conditions in your WHERE clause. With dynamic SQL, you can build the search string based on the user's actual choices. Note that while the use of Dynamic SQL offers greater flexibility, it also comes with potential security risks such as SQL Injection, and should be used judiciously. Always validate and sanitize inputs when building dynamic queries.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@Dynamic SQL in SQL Server](https://www.sqlshack.com/dynamic-sql-in-sql-server/)
- [@video@Dynamic SQL](https://www.youtube.com/watch?v=01LZMCotcpY)

View File

@@ -1,9 +1,7 @@
# FLOOR
The SQL `FLOOR` function is used to round down any specific decimal or numeric value to its nearest whole integer. The returned number will be less than or equal to the number given as an argument.
FLOOR is a numeric function that returns the largest integer value that is less than or equal to a given number. Effectively, it rounds a number *down* to the nearest whole number. For instance, FLOOR(7.9) would return 7, and FLOOR(-7.1) would return -8.
One important aspect to note is that the `FLOOR` function's argument must be a number and it always returns an integer.
Learn more from the following resources:
Visit the following resources to learn more:
- [@video@How to Round in SQL](https://www.youtube.com/watch?v=AUXw2JRwCFY)

View File

@@ -2,8 +2,7 @@
A foreign key in SQL is a column or group of columns in one table that refers to the primary key of another table. It establishes a link between two tables, enforcing referential integrity and maintaining relationships between related data. Foreign keys ensure that values in the referencing table correspond to valid values in the referenced table, preventing orphaned records and maintaining data consistency across tables. They are crucial for implementing relational database designs and supporting complex queries that join multiple tables.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@What is a foreign key?](https://www.cockroachlabs.com/blog/what-is-a-foreign-key/)
- [@video@Foreign Keys are easy (kind of)](https://www.youtube.com/watch?v=rFssfx37UJw)
- [@video@Foreign Keys are easy (kind of)](https://www.youtube.com/watch?v=rFssfx37UJw)

View File

@@ -1,9 +1,7 @@
# FROM
# FROM Clause in SELECT Statements
The `FROM` clause in SQL specifies the tables from which the retrieval should be made. It is an integral part of `SELECT` statements and variants of `SELECT` like `SELECT INTO` and `SELECT WHERE`. `FROM` can be used to join tables as well.
The `FROM` clause in SQL specifies the table or tables from which you're retrieving data. It tells the database which dataset to look at when executing your query. Without a `FROM` clause, the database doesn't know where the data is coming from, and the `SELECT` statement wouldn't be able to produce any results. Essentially, it's the foundation upon which you build your data retrieval process.
Typically, `FROM` is followed by space delimited list of tables in which the SELECT operation is to be executed. If you need to pull data from multiple tables, you would separate each table with a comma.
Learn more from the following resources:
Visit the following resources to learn more:
- [@video@How to write basic SQL](https://www.youtube.com/watch?v=YfTDBA45PHk)

View File

@@ -2,6 +2,6 @@
A `FULL OUTER JOIN` in SQL combines the results of both `LEFT` and `RIGHT OUTER JOIN`s. It returns all rows from both tables, matching records where the join condition is met and including unmatched rows from both tables with `NULL` values in place of missing data. This join type is useful when you need to see all data from both tables, regardless of whether there are matching rows, and is particularly valuable for identifying missing relationships or performing data reconciliation between two tables.
Learn more from the following resources:
Visit the following resources to learn more:
- [@video@SQL FULL OUTER JOIN](https://www.youtube.com/watch?v=XpBkXo3DCEg)

View File

@@ -2,7 +2,7 @@
`GRANT` and `REVOKE` are SQL commands used to manage user permissions in a database. `GRANT` is used to give specific privileges (such as `SELECT`, `INSERT`, `UPDATE`, `DELETE`) on database objects to users or roles, while `REVOKE` is used to remove these privileges. These commands are essential for implementing database security, controlling access to sensitive data, and ensuring that users have appropriate permissions for their roles. By using `GRANT` and `REVOKE`, database administrators can fine-tune access control, adhering to the principle of least privilege in database management.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@GRANT](https://www.ibm.com/docs/en/qmf/12.2.0?topic=privileges-sql-grant-statement)
- [@article@REVOKE](https://www.ibm.com/docs/en/qmf/12.2.0?topic=privileges-sql-revoke-statement)

View File

@@ -2,7 +2,7 @@
`GROUP BY` is an SQL clause used in `SELECT` statements to arrange identical data into groups. It's typically used with aggregate functions (like `COUNT`, `SUM`, `AVG`) to perform calculations on each group of rows. `GROUP BY` collects data across multiple records and groups the results by one or more columns, allowing for analysis of data at a higher level of granularity. This clause is fundamental for generating summary reports, performing data analysis, and creating meaningful aggregations of data in relational databases.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL GROUP BY](https://www.programiz.com/sql/group-by)
- [@video@Advanced Aggregate Functions in SQL](https://www.youtube.com/watch?v=nNrgRVIzeHg)

View File

@@ -2,7 +2,7 @@
`GROUP BY` is an SQL clause used in `SELECT` statements to arrange identical data into groups. It's typically used with aggregate functions (like `COUNT`, `SUM`, `AVG`) to perform calculations on each group of rows. `GROUP BY` collects data across multiple records and groups the results by one or more columns, allowing for analysis of data at a higher level of granularity. This clause is fundamental for generating summary reports, performing data analysis, and creating meaningful aggregations of data in relational databases.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL GROUP BY](https://www.programiz.com/sql/group-by)
- [@video@Advanced Aggregate Functions in SQL](https://www.youtube.com/watch?v=nNrgRVIzeHg)

View File

@@ -1,12 +1,8 @@
# HAVING
The `HAVING` clause is used in combination with the `GROUP BY` clause to filter the results of `GROUP BY`. It is used to mention conditions on the group functions, like `SUM`, `COUNT`, `AVG`, `MAX` or `MIN`.
The `HAVING` clause in SQL is used to filter the results of aggregate functions. It's similar to the `WHERE` clause, but operates on grouped rows produced by the `GROUP BY` clause. Essentially, `HAVING` allows you to specify conditions that groups must meet to be included in the final result set after aggregation has taken place.
It's important to note that where `WHERE` clause introduces conditions on individual rows, `HAVING` introduces conditions on groups created by the `GROUP BY` clause.
Also note, `HAVING` applies to summarized group records, whereas `WHERE` applies to individual records.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL HAVING Clause](https://www.programiz.com/sql/having)
- [@video@HAVING Clause](https://www.youtube.com/watch?v=tYBOMw7Ob8E)

View File

@@ -1,12 +1,8 @@
# HAVING
The `HAVING` clause is used in combination with the `GROUP BY` clause to filter the results of `GROUP BY`. It is used to mention conditions on the group functions, like `SUM`, `COUNT`, `AVG`, `MAX` or `MIN`.
HAVING is a clause in SQL that filters the results of a `GROUP BY` query. It's like a `WHERE` clause, but it operates on groups rather than individual rows. You use `HAVING` to specify conditions that the group must meet to be included in the final result set.
It's important to note that where `WHERE` clause introduces conditions on individual rows, `HAVING` introduces conditions on groups created by the `GROUP BY` clause.
Also note, `HAVING` applies to summarized group records, whereas `WHERE` applies to individual records.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL HAVING Clause](https://www.programiz.com/sql/having)
- [@video@HAVING Clause](https://www.youtube.com/watch?v=tYBOMw7Ob8E)

View File

@@ -2,6 +2,6 @@
Indexes in SQL are database objects that improve the speed of data retrieval operations on database tables. They work similarly to book indexes, providing a quick lookup mechanism for finding rows with specific column values. Indexes create a separate data structure that allows the database engine to locate data without scanning the entire table. While they speed up `SELECT` queries, indexes can slow down `INSERT`, `UPDATE`, and `DELETE` operations because the index structure must be updated. Proper index design is crucial for optimizing database performance, especially for large tables or frequently queried columns.
Learn more from the following resources:
Visit the following resources to learn more:
- [@video@SQL Indexing Best Practices](https://www.youtube.com/watch?v=BIlFTFrEFOI)

View File

@@ -1,13 +1,7 @@
# INNER JOIN
An `INNER JOIN` in SQL is a type of join that returns the records with matching values in both tables. This operation compares each row of the first table with each row of the second table to find all pairs of rows that satisfy the join predicate.
INNER JOINs combine rows from two or more tables based on a related column. They return only the rows where there is a match in the specified columns of all tables involved in the join. If there's no matching value in the joined columns, that row is excluded from the result set.
Few things to consider in case of `INNER JOIN`:
- It is a default join in SQL. If you mention `JOIN` in your query without specifying the type, SQL considers it as an `INNER JOIN`.
- It returns only the matching rows from both the tables.
- If there is no match, the returned is an empty result.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL INNER JOIN Clause](https://www.programiz.com/sql/inner-join)

View File

@@ -1,7 +1,7 @@
# INSERT
The "INSERT" statement is used to add new rows of data to a table in a database. There are two main forms of the INSERT command: `INSERT INTO` which, if columns are not named, expects a full set of columns, and `INSERT INTO table_name (column1, column2, ...)` where only named columns will be filled with data.
INSERT is a SQL command used to add new rows of data into a table. It specifies which table to add the data to and provides the values for each column in the new row. You can insert a single row at a time or multiple rows with a single statement.
Learn more from the following resources:
Visit the following resources to learn more:
- [@video@SQL INSERT Statement](https://www.youtube.com/watch?v=Yp1MKeIG-M4)

View File

@@ -1,7 +1,7 @@
# Insert
# INSERT Statement
The "INSERT" statement is used to add new rows of data to a table in a database. There are two main forms of the INSERT command: `INSERT INTO` which, if columns are not named, expects a full set of columns, and `INSERT INTO table_name (column1, column2, ...)` where only named columns will be filled with data.
The INSERT statement in SQL is used to add new rows of data into a table. It specifies the table to which you want to add data, and the values you want to insert into each column of that table. You can insert a single row at a time or multiple rows in a single statement. It's a fundamental command for populating your database tables with information.
Learn more from the following resources:
Visit the following resources to learn more:
- [@video@SQL INSERT Statement](https://www.youtube.com/watch?v=Yp1MKeIG-M4)

View File

@@ -1,8 +1,8 @@
# SQL JOIN Queries
# JOIN Queries
SQL `JOIN` queries combine rows from two or more tables based on a related column between them. There are several types of JOINs, including INNER JOIN (returns matching rows), `LEFT JOIN` (returns all rows from the left table and matching rows from the right), `RIGHT JOIN` (opposite of `LEFT JOIN`), and `FULL JOIN` (returns all rows when there's a match in either table). `JOIN`s are fundamental for working with relational databases, allowing users to retrieve data from multiple tables in a single query, establish relationships between tables, and perform complex data analysis across related datasets.
JOIN queries are used to combine rows from two or more tables based on a related column between them. This allows you to retrieve data from multiple tables in a single query, forming a more comprehensive dataset than you could get from a single table alone. Different types of joins, like INNER, LEFT, RIGHT, and FULL OUTER, determine how rows are included in the result based on whether matching values exist in the related columns.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@7 SQL JOIN Examples With Detailed Explanations](https://learnsql.com/blog/sql-join-examples-with-explanations/)
- [@video@Joins are easy](https://www.youtube.com/watch?v=G3lJAxg1cy8)

View File

@@ -1,14 +1,8 @@
# JOINs
SQL `JOINs` are clauses used to combine rows from two or more tables based on a related column between them. They allow retrieval of data from multiple tables in a single query, enabling complex data analysis and reporting. The main types of `JOINs` include:
- `INNER JOIN` (returns matching rows from both tables)
- `LEFT JOIN` (returns all rows from the left table and matching rows from the right)
- `RIGHT JOIN` (opposite of `LEFT JOIN`)
- `FULL JOIN` (returns all rows when there's a match in either table)
SQL JOINs let you combine data from two or more tables based on a related column between them. Think of it as linking information together to get a more complete view. The four most commonly used are: `INNER JOIN`, which returns rows only when there is a match in both tables; `LEFT JOIN`, which returns all rows from the left table and the matched rows from the right table (or NULL if there's no match); `RIGHT JOIN`, which returns all rows from the right table and the matched rows from the left table (or NULL if there's no match); and `FULL OUTER JOIN`, which returns all rows when there is a match in one of the tables.
`JOINs` are fundamental to relational database operations, facilitating data integration and exploration across related datasets.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL JOINs Cheat Sheet](https://www.datacamp.com/cheat-sheet/sql-joins-cheat-sheet)
- [@video@SQL JOINs Tutorial for beginners](https://www.youtube.com/watch?v=0OQJDd3QqQM)
- [@video@SQL JOINs Tutorial for beginners](https://www.youtube.com/watch?v=0OQJDd3QqQM)

View File

@@ -2,7 +2,7 @@
`LAG` is a window function in SQL that provides access to a row at a specified offset prior to the current row within a partition. It allows you to compare the current row's values with previous rows' values without using self-joins. LAG is particularly useful for calculating running differences, identifying trends, or comparing sequential data points in time-series analysis. The function takes the column to offset, the number of rows to offset (default is 1), and an optional default value to return when the offset goes beyond the partition's boundary.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@Understanding the LAG function in SQL](https://www.datacamp.com/tutorial/sql-lag)
- [@video@LAG and LEAD functions](https://www.youtube.com/watch?v=j2u52RQ0qlw)

View File

@@ -2,7 +2,7 @@
`LEAD` is a window function in SQL that provides access to a row at a specified offset after the current row within a partition. It's the counterpart to the `LAG` function, allowing you to look ahead in your dataset rather than behind. `LEAD` is useful for comparing current values with future values, calculating forward-looking metrics, or analyzing trends in sequential data. Like `LAG`, it takes arguments for the column to offset, the number of rows to look ahead (default is 1), and an optional default value when the offset exceeds the partition's boundary.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL LEAD](https://www.codecademy.com/resources/docs/sql/window-functions/lead)
- [@video@LAG and LEAD Window Functions in SQL](https://www.youtube.com/watch?v=nHEEyX_yDvo)

View File

@@ -1,17 +1,8 @@
# Introduction
# Learn the Basics
SQL, which stands for Structured Query Language, is a programming language that is used to communicate with and manage databases. SQL is a standard language for manipulating data held in relational database management systems (RDBMS), or for stream processing in a relational data stream management system (RDSMS). It was first developed in the 1970s by IBM.
SQL (Structured Query Language) is a programming language used to manage and manipulate data stored in relational database management systems (RDBMS). It allows you to retrieve, insert, update, and delete data, as well as define database schemas and control access to data. The basic understanding of SQL is foundational to interact with almost any database.
SQL consists of several components, each serving their own unique purpose in database communication:
- **Queries:** This is the component that allows you to retrieve data from a database. The SELECT statement is most commonly used for this purpose.
- **Data Definition Language (DDL):** It lets you create, alter, or delete databases and their related objects like tables, views, etc. Commands include CREATE, ALTER, DROP, and TRUNCATE.
- **Data Manipulation Language (DML):** It lets you manage data within database objects. These commands include SELECT, INSERT, UPDATE, and DELETE.
- **Data Control Language (DCL):** It includes commands like GRANT and REVOKE, which primarily deal with rights, permissions and other control-level management tasks for the database system.
SQL databases come in a number of forms, such as Oracle Database, Microsoft SQL Server, and MySQL. Despite their many differences, all SQL databases utilise the same language commands - SQL.
Learn more about SQL from the following resources:
Visit the following resources to learn more:
- [@article@SQL Tutorial - Mode](https://mode.com/sql-tutorial/)
- [@article@SQL Tutorial](https://www.sqltutorial.org/)
- [@article@SQL Tutorial](https://www.sqltutorial.org/)

View File

@@ -1,7 +1,7 @@
# LEFT JOIN
A `LEFT JOIN` in SQL returns all rows from the left (first) table and the matching rows from the right (second) table. If there's no match in the right table, `NULL` values are returned for those columns. This join type is useful when you want to see all records from one table, regardless of whether they have corresponding entries in another table. `LEFT JOIN`s are commonly used for finding missing relationships, creating reports that include all primary records, or when working with data where not all entries have corresponding matches in related tables.
A LEFT JOIN returns all rows from the left table (the table listed before the `LEFT JOIN` keyword) and the matching rows from the right table (the table listed after the `LEFT JOIN` keyword). If there is no match in the right table for a row in the left table, the result will contain `NULL` values for the columns from the right table. Effectively, it ensures all rows from the left table are included in the result set, regardless of whether there's a corresponding row in the right table.
Learn more from the following resources:
Visit the following resources to learn more:
- [@video@SQL LEFT JOIN - SQL Tutorial](https://www.youtube.com/watch?v=giKwmtsz1U8)

View File

@@ -2,7 +2,7 @@
The `LENGTH` function in SQL returns the number of characters in a string. It's used to measure the size of text data, which can be helpful for data validation, formatting, or analysis. In some database systems, `LENGTH` may count characters differently for multi-byte character sets. Most SQL dialects support `LENGTH`, but some may use alternative names like LEN (in SQL Server) or `CHAR_LENGTH`. This function is particularly useful for enforcing character limits, splitting strings, or identifying anomalies in string data.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@How to Check the Length of a String in SQL](https://learnsql.com/cookbook/how-to-check-the-length-of-a-string-in-sql/)
- [@article@MySQL Length Function](https://www.w3schools.com/sql/func_mysql_length.asp)

View File

@@ -2,7 +2,7 @@
The `LOWER` function in SQL converts all characters in a specified string to lowercase. It's a string manipulation function that takes a single argument (the input string) and returns the same string with all alphabetic characters converted to their lowercase equivalents. `LOWER` is useful for standardizing data, making case-insensitive comparisons, or formatting output. It doesn't affect non-alphabetic characters or numbers in the string. `LOWER` is commonly used in data cleaning, search operations, and ensuring consistent data representation across different systems.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@How to change text to lowercase in SQL](https://learnsql.com/cookbook/how-to-change-text-to-lowercase-in-sql/)
- [@article@LOWER Function](https://www.w3schools.com/sql/func_sqlserver_lower.asp)

View File

@@ -2,7 +2,7 @@
Managing indexes in SQL involves creating, modifying, and dropping indexes to optimize database performance. This process includes identifying columns that benefit from indexing (frequently queried or used in JOIN conditions), creating appropriate index types (e.g., single-column, composite, unique), and regularly analyzing index usage and effectiveness. Database administrators must balance the improved query performance that indexes provide against the overhead they introduce for data modification operations. Proper index management also includes periodic maintenance tasks like rebuilding or reorganizing indexes to maintain their efficiency as data changes over time.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL Server Indexes](https://www.sqlservercentral.com/articles/introduction-to-indexes)
- [@article@Optimize index maintenance](https://learn.microsoft.com/en-us/sql/relational-databases/indexes/reorganize-and-rebuild-indexes?view=sql-server-ver16)

View File

@@ -2,7 +2,7 @@
`MAX` is an aggregate function in SQL that returns the highest value in a set of values. It can be used with numeric, date, or string data types, selecting the maximum value from a specified column. `MAX` is often used in combination with `GROUP BY` to find the highest value within each group. This function is useful for various data analysis tasks, such as finding the highest salary, the most recent date, or the alphabetically last name in a dataset.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@MAX](https://www.techonthenet.com/sql/max.php)
- [@video@Basic Aggregate Functions](https://www.youtube.com/watch?v=jcoJuc5e3RE)

View File

@@ -2,7 +2,7 @@
`MIN` is an aggregate function in SQL that returns the lowest value in a set of values. It works with numeric, date, or string data types, selecting the minimum value from a specified column. Often used in conjunction with `GROUP BY`, `MIN` can find the smallest value within each group. This function is useful for various data analysis tasks, such as identifying the lowest price, earliest date, or alphabetically first name in a dataset.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL MAX & MIN](https://www.programiz.com/sql/min-and-max)
- [@video@COUNT, SUM, AVG, MIN, MAX (SQL) - Aggregating Data](https://www.youtube.com/watch?v=muwEdPsx534)

View File

@@ -2,6 +2,6 @@
The `MOD` function in SQL calculates the remainder when one number is divided by another. It takes two arguments: the dividend and the divisor. `MOD` returns the remainder of the division operation, which is useful for various mathematical operations, including checking for odd/even numbers, implementing cyclic behaviors, or distributing data evenly. The syntax and exact behavior may vary slightly between different database systems, with some using the % operator instead of the `MOD` keyword.
Learn more from the following resources:
Visit the following resources to learn more:
- [@video@MOD Function in SQL](https://www.youtube.com/watch?v=f1Rqf7CwjE0)

View File

@@ -1,12 +1,8 @@
# Modifying Views
In SQL, you can modify a `VIEW` in two ways:
Modifying views in SQL allows you to alter the structure or definition of an existing view without having to drop and recreate it. This can involve changing the columns included in the view, updating the underlying tables or conditions used in the view's query, or renaming the view. Using `ALTER VIEW` simplifies maintenance and allows for adjustments to views as database requirements evolve.
- Using `CREATE` OR `REPLACE VIEW`: This command helps you modify a VIEW but keeps the VIEW name intact. This is beneficial when you want to change the definition of the `VIEW` but do not want to change the VIEW name.
- Using the `DROP VIEW` and then `CREATE VIEW`: In this method, you first remove the `VIEW` using the `DROP VIEW` command and then recreate the view using the new definition with the `CREATE VIEW` command.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@Modify Views in SQL Server](https://www.sqlshack.com/create-view-sql-modifying-views-in-sql-server/)
- [@video@SQL VIEWs in 4 Minutes](https://www.youtube.com/watch?v=vLLkNI-vkV8)

View File

@@ -1,10 +1,8 @@
# Nested Subqueries
In SQL, a subquery is a query that is nested inside a main query. If a subquery is nested inside another subquery, it is called a nested subquery. They can be used in SELECT, INSERT, UPDATE, or DELETE statements or inside another subquery.
Nested subqueries are queries embedded within another SQL query. Think of it as a query inside a query, where the inner query's result is used by the outer query. This allows you to perform more complex data retrieval and filtering operations by breaking down a larger problem into smaller, more manageable steps. Essentially, the outer query depends on the result returned by the inner query to complete its own operation.
Nested subqueries can get complicated quickly, but they are essential for performing complex database tasks.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@Nested Subqueries](https://www.studysmarter.co.uk/explanations/computer-science/databases/nested-subqueries-in-sql/)
- [@video@MySQL Subqueries](https://www.youtube.com/watch?v=i5acg3Hvu6g)

View File

@@ -1,10 +1,8 @@
# NOT NULL
# NOT NULL Constraint
The `NOT NULL` constraint in SQL ensures that a column cannot have a NULL value. Thus, every row/record must contain a value for that column. It is a way to enforce certain fields to be mandatory while inserting records or updating records in a table.
The NOT NULL constraint in SQL ensures that a column does not accept null values. When a column is defined with this constraint, every row in the table must have a value for that specific column. Attempting to insert or update a row with a null value in a NOT NULL column will result in an error, maintaining data integrity by preventing missing or undefined entries.
For instance, if you're designing a table for employee data, you might want to ensure that the employee's `id` and `name` are always provided. In this case, you'd use the `NOT NULL` constraint.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL IS NULL and IS NOT NULL](https://www.programiz.com/sql/is-null-not-null)
- [@video@NOT NULL Constraint](https://www.youtube.com/watch?v=unzHhq82mKU)

View File

@@ -2,6 +2,6 @@
`NULLIF` is an SQL function that compares two expressions and returns NULL if they are equal, otherwise it returns the first expression. It's particularly useful for avoiding division by zero errors or for treating specific values as `NULL` in calculations or comparisons. `NULLIF` takes two arguments and is often used in combination with aggregate functions or in `CASE` statements to handle special cases in data processing or reporting.
Learn more from the following resources:
Visit the following resources to learn more:
- [@video@What is NULLIF in SQL?](https://www.youtube.com/watch?v=Jaw53T__RRY)

View File

@@ -2,6 +2,6 @@
SQL operators are symbols or keywords used to perform operations on data within a database. They are essential for constructing queries that filter, compare, and manipulate data. Common types of operators include arithmetic operators (e.g., `+`, `-`, `*`, `/`), which perform mathematical calculations; comparison operators (e.g., `=`, `!=`, `<`, `>`), used to compare values; logical operators (e.g., `AND`, `OR`, `NOT`), which combine multiple conditions in a query; and set operators (e.g., `UNION`, `INTERSECT`, `EXCEPT`), which combine results from multiple queries. These operators enable precise control over data retrieval and modification.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL Operators: 6 Different Types](https://dataengineeracademy.com/blog/sql-operators-6-different-types-code-examples/)

View File

@@ -2,7 +2,7 @@
Optimizing joins in SQL involves techniques to improve the performance of queries that combine data from multiple tables. Key strategies include using appropriate join types (e.g., `INNER JOIN` for matching rows only, `LEFT JOIN` for all rows from one table), indexing the columns used in join conditions to speed up lookups, and minimizing the data processed by filtering results with `WHERE` clauses before the join. Additionally, reducing the number of joins, avoiding unnecessary columns in the `SELECT` statement, and ensuring that the join conditions are based on indexed and selective columns can significantly enhance query efficiency. Proper join order and using database-specific optimization hints are also important for performance tuning.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@How to Optimize a SQL Query with Multiple Joins](https://dezbor.com/blog/optimize-sql-query-with-multiple-joins)
- [@video@Secret to optimizing SQL queries](https://www.youtube.com/watch?v=BHwzDmr6d7s)

View File

@@ -2,6 +2,6 @@
The `ORDER BY` clause in SQL is used to sort the result set of a query by one or more columns. By default, the sorting is in ascending order, but you can specify descending order using the `DESC` keyword. The clause can sort by numeric, date, or text values, and multiple columns can be sorted by listing them in the `ORDER BY` clause, each with its own sorting direction. This clause is crucial for organizing data in a meaningful sequence, such as ordering by a timestamp to show the most recent records first, or alphabetically by name.
Learn more from the following resources:
Visit the following resources to learn more:
- [@video@SQL ORDER BY Sorting Clause](https://www.youtube.com/watch?v=h_HHTNjAgS8)

View File

@@ -1,8 +1,8 @@
# Performance Optimization
Performance optimization in SQL involves a set of practices aimed at improving the efficiency and speed of database queries and overall system performance. Key strategies include indexing critical columns to speed up data retrieval, optimizing query structure by simplifying or refactoring complex queries, and using techniques like query caching to reduce redundant database calls. Other practices include reducing the use of resource-intensive operations like `JOINs` and `GROUP BY`, selecting only necessary columns (`SELECT *` should be avoided), and leveraging database-specific features such as partitioning, query hints, and execution plan analysis. Regularly monitoring and analyzing query performance, along with maintaining database health through routine tasks like updating statistics and managing indexes, are also vital to sustaining high performance.
Performance optimization in SQL focuses on making your queries run faster and more efficiently. This involves techniques like using indexes to speed up data retrieval, rewriting queries for better performance, and understanding how the database engine executes your SQL code. It's about ensuring your database can handle large amounts of data and complex queries without slowing down.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@Performance Tuning SQL Queries](https://mode.com/sql-tutorial/sql-performance-tuning)
- [@article@SQL performance tuning](https://stackify.com/performance-tuning-in-sql-server-find-slow-queries/)

View File

@@ -1,8 +1,8 @@
# Pivot and Unpivot Operations
# Pivot / Unpivot Operations
Pivot and Unpivot operations in SQL are used to transform and reorganize data, making it easier to analyze in different formats. The `PIVOT` operation converts rows into columns, allowing you to summarize data and present it in a more readable, table-like format. For example, it can take sales data by month and convert the months into individual columns. Conversely, the `UNPIVOT` operation does the opposite—it converts columns back into rows, which is useful for normalizing data that was previously pivoted or to prepare data for certain types of analysis. These operations are particularly useful in reporting and data visualization scenarios, where different perspectives on the same data set are required.
Pivot and unpivot operations transform the structure of data within a table. Pivoting rotates rows into columns, aggregating data based on common values. Conversely, unpivoting transforms columns into rows, often expanding a table's length while reducing its width. These operations are useful for reshaping data for reporting or analysis.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL PIVOT](https://builtin.com/articles/sql-pivot)
- [@article@SQL UNPIVOT](https://duckdb.org/docs/sql/statements/unpivot.html)

View File

@@ -2,6 +2,6 @@
A primary key in SQL is a unique identifier for each record in a database table. It ensures that each row in the table is uniquely identifiable, meaning no two rows can have the same primary key value. A primary key is composed of one or more columns, and it must contain unique values without any `NULL` entries. The primary key enforces entity integrity by preventing duplicate records and ensuring that each record can be precisely located and referenced, often through foreign key relationships in other tables. Using a primary key is fundamental for establishing relationships between tables and maintaining the integrity of the data model.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL Primary Key](https://www.tutorialspoint.com/sql/sql-primary-key.htm)

View File

@@ -1,8 +1,8 @@
# Query Analysis Techniques
Query analysis techniques in SQL involve examining and optimizing queries to improve performance and efficiency. Key techniques include using `EXPLAIN` or `EXPLAIN PLAN` commands to understand the query execution plan, which reveals how the database processes the query, including join methods, index usage, and data retrieval strategies. Analyzing `execution plans` helps identify bottlenecks such as full table scans or inefficient joins. Other techniques include `profiling queries` to measure execution time, `examining indexes` to ensure they are effectively supporting query operations, and `refactoring queries` by breaking down complex queries into simpler, more efficient components. Additionally, monitoring `database performance metrics` like CPU, memory usage, and disk I/O can provide insights into how queries impact overall system performance. Regularly applying these techniques allows for the identification and resolution of performance issues, leading to faster and more efficient database operations.
Understanding how SQL queries are executed is essential for performance tuning. Tools like `EXPLAIN` or `EXPLAIN PLAN` allow you to dissect the execution plan the database uses for a specific query. This plan reveals the order in which tables are accessed, the types of indexes used (or not used), and the estimated cost of each operation, enabling you to identify bottlenecks and optimize the query for faster execution.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@EXPLAIN](https://docs.snowflake.com/en/sql-reference/sql/explain)
- [@article@EXPLAIN PLAN](https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/EXPLAIN-PLAN.html)

View File

@@ -1,8 +1,8 @@
# Query Optimization
Query optimization in SQL involves refining queries to enhance their execution speed and reduce resource consumption. Key strategies include indexing columns used in `WHERE`, `JOIN`, and `ORDER BY` clauses to accelerate data retrieval, minimizing data processed by limiting the number of columns selected and filtering rows early in the query. Using appropriate join types and arranging joins in the most efficient order are crucial. Avoiding inefficient patterns like `SELECT *`, replacing subqueries with joins or common table expressions (CTEs), and leveraging query hints or execution plan analysis can also improve performance. Regularly updating statistics and ensuring that queries are structured to take advantage of database-specific optimizations are essential practices for maintaining optimal performance.
Query optimization is the process of selecting the most efficient way to execute a SQL query. It involves the database management system (DBMS) analyzing different possible execution plans for a query and choosing the one that will return the results fastest, using the least amount of resources. This analysis considers factors like the data volume, index usage, and system resources to find the optimal path.
Learn more from the following resources:
Visit the following resources to learn more:
- [@video@SQL Query Optimization](https://www.youtube.com/watch?v=GA8SaXDLdsY)
- [@article@12 Ways to Optimize SQL Queries](https://www.developernation.net/blog/12-ways-to-optimize-sql-queries-in-database-management/)
- [@article@12 Ways to Optimize SQL Queries](https://www.developernation.net/blog/12-ways-to-optimize-sql-queries-in-database-management/)
- [@video@SQL Query Optimization](https://www.youtube.com/watch?v=GA8SaXDLdsY)

View File

@@ -2,7 +2,7 @@
The `RANK` function in SQL is a window function that assigns a rank to each row within a partition of a result set, based on the order specified by the `ORDER BY` clause. Unlike the `ROW_NUMBER` function, `RANK` allows for the possibility of ties—rows with equal values in the ordering column(s) receive the same rank, and the next rank is skipped accordingly. For example, if two rows share the same rank of 1, the next rank will be 3. This function is useful for scenarios where you need to identify relative positions within groups, such as ranking employees by salary within each department.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@Overview of SQL RANK Functions](https://www.sqlshack.com/overview-of-sql-rank-functions/)
- [@video@RANK, DENSE_RANK, ROW_NUMBER SQL Analytical Functions Simplified](https://www.youtube.com/watch?v=xMWEVFC4FOk)

View File

@@ -1,31 +1,7 @@
# RDBMS Benefits and Limitations
Here are some of the benefits of using an RDBMS:
Relational Database Management Systems (RDBMS) organize data into tables with rows and columns, establishing relationships between these tables using keys. This structured approach offers benefits like data integrity through constraints and ACID properties (Atomicity, Consistency, Isolation, Durability), ensuring reliable transactions. However, RDBMS can face limitations regarding scalability, especially with massive datasets, and may not be the optimal choice for handling unstructured or semi-structured data due to their rigid schema.
- **Structured Data**: RDBMS allows data storage in a structured way, using rows and columns in tables. This makes it easy to manipulate the data using SQL (Structured Query Language), ensuring efficient and flexible usage.
- **ACID Properties**: ACID stands for Atomicity, Consistency, Isolation, and Durability. These properties ensure reliable and safe data manipulation in a RDBMS, making it suitable for mission-critical applications.
- **Normalization**: RDBMS supports data normalization, a process that organizes data in a way that reduces data redundancy and improves data integrity.
- **Scalability**: RDBMSs generally provide good scalability options, allowing for the addition of more storage or computational resources as the data and workload grow.
- **Data Integrity**: RDBMS provides mechanisms like constraints, primary keys, and foreign keys to enforce data integrity and consistency, ensuring that the data is accurate and reliable.
- **Security**: RDBMSs offer various security features such as user authentication, access control, and data encryption to protect sensitive data.
Here are some of the limitations of using an RDBMS:
- **Complexity**: Setting up and managing an RDBMS can be complex, especially for large applications. It requires technical knowledge and skills to manage, tune, and optimize the database.
- **Cost**: RDBMSs can be expensive, both in terms of licensing fees and the computational and storage resources they require.
- **Fixed Schema**: RDBMS follows a rigid schema for data organization, which means any changes to the schema can be time-consuming and complicated.
- **Handling of Unstructured Data**: RDBMSs are not suitable for handling unstructured data like multimedia files, social media posts, and sensor data, as their relational structure is optimized for structured data.
- **Horizontal Scalability**: RDBMSs are not as easily horizontally scalable as NoSQL databases. Scaling horizontally, which involves adding more machines to the system, can be challenging in terms of cost and complexity.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@Advantages and Disadvantages of DBMS](https://cloud.google.com/learn/what-is-a-relational-database)

View File

@@ -1,8 +1,8 @@
# Recursive Queries
Recursive queries in SQL allow for the repeated execution of a query within itself, enabling the traversal of hierarchical or tree-like data structures. This powerful feature is particularly useful for handling nested relationships, such as organizational hierarchies, bill of materials, or network topologies. By using a combination of an anchor member (initial query) and a recursive member (the part that refers to itself), recursive queries can iterate through multiple levels of data, retrieving information that would be difficult or impossible to obtain with standard SQL constructs. This technique simplifies complex queries and improves performance when dealing with self-referential data.
Recursive queries are SQL queries that refer to themselves within their own definition. They're used to process hierarchical or tree-structured data, where relationships exist between rows in the same table, like organizational charts, bill of materials, or social networks. Using `WITH RECURSIVE` clause, these queries iterate through the data until a certain condition is met, allowing you to traverse the hierarchy and extract related information.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@Recursive Queries in SQL](https://codedamn.com/news/sql/recursive-queries-in-sql)
- [@article@Recursive SQL Expression Visually Explained](https://builtin.com/data-science/recursive-sql)

View File

@@ -2,6 +2,6 @@
The `REPLACE` function in SQL is used to substitute all occurrences of a specified substring within a string with a new substring. It takes three arguments: the original string, the substring to be replaced, and the substring to replace it with. If the specified substring is found in the original string, `REPLACE` returns the modified string with all instances of the old substring replaced by the new one. If the substring is not found, the original string is returned unchanged. This function is particularly useful for data cleaning tasks, such as correcting typos, standardizing formats, or replacing obsolete data.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@How to use the SQL REPLACE Function](https://www.datacamp.com/tutorial/sql-replace)

View File

@@ -1,7 +1,7 @@
# RIGHT JOIN
A `RIGHT JOIN` in SQL is a type of outer join that returns all rows from the right (second) table and the matching rows from the left (first) table. If there's no match in the left table, `NULL` values are returned for the left table's columns. This join type is less commonly used than LEFT JOIN but is particularly useful when you want to ensure all records from the second table are included in the result set, regardless of whether they have corresponding matches in the first table. `RIGHT JOIN` is often used to identify missing relationships or to include all possible values from a lookup table.
A RIGHT JOIN combines rows from two tables based on a related column. It returns all rows from the right table (the table specified after the `RIGHT JOIN` keyword), and the matching rows from the left table. If there's no match in the left table for a row in the right table, `NULL` values are returned for the columns from the left table in the result set.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL RIGHT JOIN With Examples](https://www.programiz.com/sql/right-join)

View File

@@ -2,7 +2,7 @@
`ROLLBACK` is a SQL command used to undo transactions that have not yet been committed to the database. It reverses all changes made within the current transaction, restoring the database to its state before the transaction began. This command is crucial for maintaining data integrity, especially when errors occur during a transaction or when implementing conditional logic in database operations. `ROLLBACK` is an essential part of the ACID (Atomicity, Consistency, Isolation, Durability) properties of database transactions, ensuring that either all changes in a transaction are applied, or none are, thus preserving data consistency.
Learn more from the following resources:
Visit the following resources to learn more:
- [@video@How to undo a mistake a in SQL: Rollback and Commit](https://www.youtube.com/watch?v=jomsdMLiIZM)
- [@article@Difference between COMMIT and ROLLBACK in SQL](https://byjus.com/gate/difference-between-commit-and-rollback-in-sql/)
- [@article@Difference between COMMIT and ROLLBACK in SQL](https://byjus.com/gate/difference-between-commit-and-rollback-in-sql/)
- [@video@How to undo a mistake a in SQL: Rollback and Commit](https://www.youtube.com/watch?v=jomsdMLiIZM)

View File

@@ -2,6 +2,6 @@
The `ROUND` function in SQL is used to round a numeric value to a specified number of decimal places. It takes two arguments: the number to be rounded and the number of decimal places to round to. If the second argument is omitted, the function rounds the number to the nearest whole number. For positive values of the second argument, the number is rounded to the specified decimal places; for negative values, it rounds to the nearest ten, hundred, thousand, etc. The `ROUND` function is useful for formatting numerical data for reporting or ensuring consistent precision in calculations.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@What is the SQL ROUND Function and how does it work?](https://www.datacamp.com/tutorial/mastering-sql-round)

View File

@@ -2,7 +2,7 @@
In SQL, a row (also called a record or tuple) represents a single, implicitly structured data item in a table. Each row contains a set of related data elements corresponding to the table's columns. Rows are fundamental to the relational database model, allowing for the organized storage and retrieval of information. Operations like INSERT, UPDATE, and DELETE typically work at the row level.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@Row - Database](https://en.wikipedia.org/wiki/Row_(database))
- [@article@Database Row: Definition, Examples](https://www.devx.com/terms/database-row/)

View File

@@ -1,8 +1,8 @@
# Row_number
ROW_NUMBER() is a SQL window function that assigns a unique, sequential integer to each row within a partition of a result set. It's useful for creating row identifiers, implementing pagination, or finding the nth highest/lowest value in a group. The numbering starts at 1 for each partition and continues sequentially, allowing for versatile data analysis and manipulation tasks.
ROW\_NUMBER() is a SQL window function that assigns a unique, sequential integer to each row within a partition of a result set. It's useful for creating row identifiers, implementing pagination, or finding the nth highest/lowest value in a group. The numbering starts at 1 for each partition and continues sequentially, allowing for versatile data analysis and manipulation tasks.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL ROW_NUMBER](https://www.sqltutorial.org/sql-window-functions/sql-row_number/)
- [@article@How to Use ROW_NUMBER OVER() in SQL to Rank Data](https://learnsql.com/blog/row-number-over-in-sql/)

View File

@@ -2,7 +2,7 @@
A `SAVEPOINT` in SQL is a point within a transaction that can be referenced later. It allows for more granular control over transactions by creating intermediate points to which you can roll back without affecting the entire transaction. This is particularly useful in complex transactions where you might want to undo part of the work without discarding all changes. `SAVEPOINT` enhances transaction management flexibility.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL SAVEPOINT](https://www.ibm.com/docs/pl/informix-servers/12.10?topic=statements-savepoint-statement)
- [@video@DBMS - Save Point](https://www.youtube.com/watch?v=30ldSUkswGM)

View File

@@ -2,7 +2,7 @@
A scalar value is a single data item, as opposed to a set or array of values. Scalar subqueries are queries that return exactly one column and one row, often used in `SELECT` statements, `WHERE` clauses, or as part of expressions. Scalar functions in SQL return a single value based on input parameters. Understanding scalar concepts is crucial for writing efficient and precise SQL queries.
Learn more from the following resources:
Visit the following resources to learn more:
- [@video@Using Scalar SQL to boost performance](https://www.youtube.com/watch?v=v8X5FGzzc9A)
- [@article@Creating SQL Scalar Functions](https://www.ibm.com/docs/en/db2/11.5?topic=functions-creating-sql-scalar)
- [@article@Creating SQL Scalar Functions](https://www.ibm.com/docs/en/db2/11.5?topic=functions-creating-sql-scalar)
- [@video@Using Scalar SQL to boost performance](https://www.youtube.com/watch?v=v8X5FGzzc9A)

View File

@@ -1,7 +1,3 @@
# SELECT
SELECT is one of the most fundamental SQL commands, used to retrieve data from one or more tables in a database. It allows you to specify which columns to fetch, apply filtering conditions, sort results, and perform various operations on the data. The SELECT statement is versatile, supporting joins, subqueries, aggregations, and more, making it essential for data querying and analysis in relational databases.
Learn more from the following resources:
# Select Statement
The `SELECT` statement in SQL is used to retrieve data from one or more tables. It allows you to specify which columns you want to see and apply conditions to filter the rows returned. Think of it as a powerful tool to query a database and extract specific information based on your needs.

View File

@@ -1,6 +1,3 @@
# SELECT statement
SELECT is one of the most fundamental SQL commands, used to retrieve data from one or more tables in a database. It allows you to specify which columns to fetch, apply filtering conditions, sort results, and perform various operations on the data. The SELECT statement is versatile, supporting joins, subqueries, aggregations, and more, making it essential for data querying and analysis in relational databases.
Learn more from the following resources:
# SELECT statement
SELECT is one of the most fundamental SQL commands, used to retrieve data from one or more tables in a database. It allows you to specify which columns to fetch, apply filtering conditions, sort results, and perform various operations on the data. The SELECT statement is versatile, supporting joins, subqueries, aggregations, and more, making it essential for data querying and analysis in relational databases.

View File

@@ -1,3 +1,3 @@
# Selective Projection
Selective projection in SQL refers to the practice of choosing only specific columns (attributes) from a table or query result, rather than selecting all available columns. This technique is crucial for optimizing query performance and reducing unnecessary data transfer. By using SELECT with explicitly named columns instead of `SELECT *`, developers can improve query efficiency and clarity, especially when dealing with large tables or complex joins.
Selective projection in SQL refers to the practice of choosing only specific columns (attributes) from a table or query result, rather than selecting all available columns. This technique is crucial for optimizing query performance and reducing unnecessary data transfer. By using SELECT with explicitly named columns instead of `SELECT *`, developers can improve query efficiency and clarity, especially when dealing with large tables or complex joins.

View File

@@ -1,10 +1,8 @@
# Self Join
A `SELF JOIN` is a standard SQL operation where a table is joined to itself. This might sound counter-intuitive, but it's actually quite useful in scenarios where comparison operations need to be made within a table. Essentially, it is used to combine rows with other rows in the same table when there's a match based on the condition provided.
A self join is a query in SQL that joins a table to itself. This is useful when you want to compare rows within the same table, often based on a hierarchical relationship or other connection between the data points within that table. Think of it as creating two copies of the same table and then joining them based on a shared column, allowing you to relate data from the same source in a new way.
It's important to note that, since it's a join operation on the same table, alias(es) for table(s) must be used to avoid confusion during the join operation.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@Understanding the Self Joins in SQL](https://www.dbvis.com/thetable/understanding-self-joins-in-sql/)
- [@article@SQL self joins](https://www.w3schools.com/sql/sql_join_self.asp)

View File

@@ -2,6 +2,6 @@
SQL keywords are reserved words that have special meanings within SQL statements. These include commands (like `SELECT`, `INSERT`, `UPDATE`), clauses (such as `WHERE`, `GROUP BY`, `HAVING`), and other syntax elements that form the structure of SQL queries. Understanding SQL keywords is fundamental to writing correct and effective database queries. Keywords are typically case-insensitive but are often written in uppercase by convention for better readability.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL Keywords, Operators and Statements](https://blog.hubspot.com/website/sql-keywords-operators-statements)

View File

@@ -2,7 +2,7 @@
SQL (relational) and NoSQL (non-relational) databases represent two different approaches to data storage and retrieval. SQL databases use structured schemas and tables, emphasizing data integrity and complex queries through joins. NoSQL databases offer more flexibility in data structures, often sacrificing some consistency for scalability and performance. The choice between SQL and NoSQL depends on factors like data structure, scalability needs, consistency requirements, and the nature of the application.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@Understanding SQL vs NoSQL Databases](https://www.mongodb.com/resources/basics/databases/nosql-explained/nosql-vs-sql)
- [@video@SQL vs NoSQL Databases in 4 mins](https://www.youtube.com/watch?v=_Ss42Vb1SU4)

View File

@@ -2,6 +2,6 @@
Stored procedures and functions are precompiled database objects that encapsulate a set of SQL statements and logic. Stored procedures can perform complex operations and are typically used for data manipulation, while functions are designed to compute and return values. Both improve performance by reducing network traffic and allowing code reuse. They also enhance security by providing a layer of abstraction between the application and the database.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@Stored Procedure vs Functions](https://www.shiksha.com/online-courses/articles/stored-procedure-vs-function-what-are-the-differences/)

View File

@@ -2,7 +2,7 @@
Subqueries, also known as nested queries or inner queries, are SQL queries embedded within another query. They can be used in various parts of SQL statements, such as SELECT, FROM, WHERE, and HAVING clauses. Subqueries allow for complex data retrieval and manipulation by breaking down complex queries into more manageable parts. They're particularly useful for creating dynamic criteria, performing calculations, or comparing sets of results.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL Sub Queries](https://www.tutorialspoint.com/sql/sql-sub-queries.htm)
- [@video@Advanced SQL Tutorial | Subqueries](https://www.youtube.com/watch?v=m1KcNV-Zhmc)

View File

@@ -2,7 +2,7 @@
SUBSTRING is a SQL function used to extract a portion of a string. It allows you to specify the starting position and length of the substring you want to extract. This function is valuable for data manipulation, parsing, and formatting tasks. The exact syntax may vary slightly between database systems, but the core functionality remains consistent, making it a versatile tool for working with string data in databases.
Learn more from the following resources:
Visit the following resources to learn more:
- [@video@Advanced SQL Tutorial | String Functions + Use Cases](https://www.youtube.com/watch?v=GQj6_6V_jVA)
- [@article@SQL SUBSTRING](https://www.w3schools.com/sql/func_sqlserver_substring.asp)
- [@article@SQL SUBSTRING](https://www.w3schools.com/sql/func_sqlserver_substring.asp)
- [@video@Advanced SQL Tutorial | String Functions + Use Cases](https://www.youtube.com/watch?v=GQj6_6V_jVA)

View File

@@ -2,6 +2,6 @@
SUM is an aggregate function in SQL used to calculate the total of a set of values. It's commonly used with numeric columns in combination with GROUP BY clauses to compute totals for different categories or groups within the data. SUM is essential for financial calculations, statistical analysis, and generating summary reports from database tables. It ignores NULL values and can be used in conjunction with other aggregate functions for complex data analysis.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@SQL SUM](https://www.studysmarter.co.uk/explanations/computer-science/databases/sql-sum/)

View File

@@ -2,7 +2,7 @@
A table is a fundamental structure for organizing data in a relational database. It consists of rows (records) and columns (fields), representing a collection of related data entries. Tables define the schema of the data, including data types and constraints. They are the primary objects for storing and retrieving data in SQL databases, and understanding table structure is crucial for effective database design and querying.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@Table (Database)](https://en.wikipedia.org/wiki/Table_(database))
- [@article@Introduction to Tables](https://support.microsoft.com/en-gb/office/introduction-to-tables-78ff21ea-2f76-4fb0-8af6-c318d1ee0ea7)

View File

@@ -2,5 +2,4 @@
The TIME data type in SQL is used to store time values, typically in the format of hours, minutes, and seconds. It's useful for recording specific times of day without date information. SQL provides various functions for manipulating and comparing TIME values, allowing for time-based calculations and queries. The exact range and precision of TIME can vary between different database management systems.
Learn more from the following resources:
Learn more from the following resources:

View File

@@ -1,9 +1,7 @@
# TIMESTAMP
SQL `TIMESTAMP` is a data type that allows you to store both date and time. It is typically used to track updates and changes made to a record, providing a chronological time of happenings.
A TIMESTAMP is a data type used to store a specific point in time, typically including both date and time components. It often includes fractions of a second (milliseconds or microseconds) for greater precision. It is very common for databases to have a timestamp that automatically updates when a row is updated.
Depending on the SQL platform, the format and storage size can slightly vary. For instance, MySQL uses the 'YYYY-MM-DD HH:MI:SS' format and in PostgreSQL, it's stored as a 'YYYY-MM-DD HH:MI:SS' format but it additionally can store microseconds.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@Different SQL TimeStamp functions in SQL Server](https://www.sqlshack.com/different-sql-timestamp-functions-in-sql-server/)

View File

@@ -2,7 +2,7 @@
Transaction isolation levels in SQL define the degree to which the operations in one transaction are visible to other concurrent transactions. There are typically four standard levels: Read Uncommitted, Read Committed, Repeatable Read, and Serializable. Each level provides different trade-offs between data consistency and concurrency. Understanding and correctly setting isolation levels is crucial for maintaining data integrity and optimizing performance in multi-user database environments.
Learn more from the following resources:
Visit the following resources to learn more:
- [@article@Everything you always wanted to know about SQL isolation levels](https://www.cockroachlabs.com/blog/sql-isolation-levels-explained/)
- [@article@Isolation Levels in SQL Server](https://www.sqlservercentral.com/articles/isolation-levels-in-sql-server)

View File

@@ -2,7 +2,7 @@
Transactions in SQL are units of work that group one or more database operations into a single, atomic unit. They ensure data integrity by following the ACID properties: Atomicity (all or nothing), Consistency (database remains in a valid state), Isolation (transactions don't interfere with each other), and Durability (committed changes are permanent). Transactions are essential for maintaining data consistency in complex operations and handling concurrent access to the database.
Learn more from the following resources:
Visit the following resources to learn more:
- [@articles@Transactions](https://www.tutorialspoint.com/sql/sql-transactions.htm)
- [@article@Transactions](https://www.tutorialspoint.com/sql/sql-transactions.htm)
- [@article@A Guide to ACID Properties in Database Management Systems](https://www.mongodb.com/resources/basics/databases/acid-transactions)

Some files were not shown because too many files have changed in this diff Show More