Skip to content

Commit

Permalink
added sql_best_practices
Browse files Browse the repository at this point in the history
  • Loading branch information
adhikareeprayush committed May 8, 2024
1 parent 0acbac7 commit 5e9068d
Showing 1 changed file with 213 additions and 0 deletions.
213 changes: 213 additions & 0 deletions topics/sql_best_practices.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="../css/tutorial.css">
<link rel="stylesheet" href="../css/default.css">
<title>Learn SQL | Filtering Data</title>
</head>

<body>
<div class="sidenav">
<div class="logo">
<a href="../index.html" class="header">Learn SQL</a>
<p>With <a href="#">Me😊</a></p>
</div>
<div class="topics">
<a href="database.html" class="topic">Database</a>
<a href="basic_sql_queries.html" class="topic">Basic SQL Queries</a>
<a href="#" class="topic ">Filtering Data</a>
<a href="working_with_functions.html" class="topic">Working with Functions</a>
<a href="joining_tables.html" class="topic">Joining Tables</a>
<a href="sub_queries.html" class="topic">Subqueries</a>
<a href="modifying_data.html" class="topic">Modifying Data</a>
<a href="advanced_queries.html" class="topic">Advanced Queries</a>
<a href="transactions_and_locking.html" class="topic ">Transactions and Locking</a>
<a href="indexing_and_optimization.html" class="topic active">Indexing and Optimization</a>
<a href="sql_best_practices.html" class="topic">SQL Best Practices</a>
</div>
<div class="social-icons">
<!-- linkedin -->
<a href="https://www.linkedin.com/in/prayushadhikari/" class="social-link">
<i class="bi bi-linkedin"></i>
</a>
<!-- github -->
<a href="https://www.github.com/adhikareeprayush" class="social-link">
<i class="bi bi-github"></i>
</a>
<!-- twitter -->
<a href="https://www.twitter.com/prayushadhikari" class="social-link">
<i class="bi bi-twitter"></i>
</a>
<!-- instagram -->
<a href="https://www.instagram.com/prayushadhikari" class="social-link">
<i class="bi bi-instagram"></i>
</a>


</div>

</div>

<div class="content">
<div class="subtopics">
<div id="indexes_in_sql" class="id_topic">
<div class="question">
<h2>Indexes in SQL</h2>
<p>Indexes are used to retrieve data from the database more quickly than otherwise. The users cannot
see the indexes, they are just used to speed up searches/queries.</p>

<h3>Types of Indexes</h3>
<p>There are three types of indexes:</p>
<ul>
<li>- Unique Index</li>
<li>- Clustered Index</li>
<li>- Non-Clustered Index</li>
</ul>

<h3>Unique Index</h3>
<p>Unique Indexes are used not just for performance but for data integrity as well, as they do not
allow the field to have duplicate values if the column is unique indexed.</p>

<h3>Clustered Index</h3>
<p>Clustered Indexes are the indexes that physically sort the data rows in the table on the basis of
their key values. There can be only one clustered index on a table.</p>

<h3>Non-Clustered Index</h3>
<p>Non-Clustered Indexes are the indexes where the logical order of the index does not match the
physical stored order of the rows on disk. The leaf layer of a non-clustered index does not
consist
of the data pages. Instead, the leaf nodes contain index rows.</p>

</div>
</div>

<div id="query_optimization_techniques" class="id_topic">
<div class="question">
<h2>Query Optimization Techniques</h2>
<p>Query optimization is the process of selecting the most efficient way to execute a query. The
process of optimization is a complex one, as it involves making decisions based on the available
statistics and the query plan. The query optimizer is the component of the database management
system that performs this optimization.</p>

<h3>Types of Query Optimization Techniques</h3>
<p>There are several query optimization techniques:</p>
<ul>
<li>- Join Elimination</li>
<li>- Indexing</li>
<li>- Query Rewriting</li>
<li>- Query Decomposition</li>
<li>- Query Compilation</li>
<li>- Query Execution</li>
</ul>

<h3>Join Elimination</h3>
<p>Join elimination is the process of removing joins from a query that are not necessary for the
query to return the correct results. This can be done by using indexes or by rewriting the query
to eliminate the join.</p>

<h3>Indexing</h3>
<p>Indexing is the process of creating indexes on the columns that are frequently used in queries.
This can speed up the query by allowing the database to quickly locate the rows that match the
query criteria.</p>

<h3>Query Rewriting</h3>
<p>Query rewriting is the process of rewriting a query to make it more efficient. This can involve
changing the order of operations in the query or rewriting the query to use a different
algorithm.</p>

<h3>Query Decomposition</h3>
<p>Query decomposition is the process of breaking a complex query into smaller, simpler queries that
can be executed more efficiently. This can be done by using subqueries or by rewriting the query
to eliminate unnecessary operations.</p>

<h3>Query Compilation</h3>
<p>Query compilation is the process of compiling a query into an executable form that can be
executed by the database engine. This can involve optimizing the query plan and generating
efficient code to execute the query.</p>

<h3>Query Execution</h3>
<p>Query execution is the process of executing the compiled query and returning the results to the
user. This can involve reading data from disk, processing the data, and returning the results to
the user.</p>



</div>
</div>

<div id="normalization_and_denormalization" class="id_topic">
<div class="question">
<h2>Normalization and Denormalization</h2>
<p>Normalization is the process of organizing data in a database. This includes creating tables and
establishing relationships between those tables according to rules designed both to protect the
data and to make the database more flexible by eliminating redundancy and inconsistent
dependency.</p>

<h3>Types of Normalization</h3>
<p>There are several types of normalization:</p>
<ul>
<li>- First Normal Form (1NF)</li>
<li>- Second Normal Form (2NF)</li>
<li>- Third Normal Form (3NF)</li>
<li>- Boyce-Codd Normal Form (BCNF)</li>
<li>- Fourth Normal Form (4NF)</li>
<li>- Fifth Normal Form (5NF)</li>
</ul>

<h3>First Normal Form (1NF)</h3>
<p>First Normal Form (1NF) is the first step in the normalization process. It requires that the
table
have a primary key and that each column in the table contain only atomic values.</p>

<h3>Second Normal Form (2NF)</h3>
<p>Second Normal Form (2NF) requires that the table be in 1NF and that all non-key attributes be
fully
functionally dependent on the primary key.</p>

<h3>Third Normal Form (3NF)</h3>
<p>Third Normal Form (3NF) requires that the table be in 2NF and that all non-key attributes be
non-transitively dependent on the primary key.</p>

<h3>Boyce-Codd Normal Form (BCNF)</h3>
<p>Boyce-Codd Normal Form (BCNF) requires that the table be in 3NF and that all determinants be
candidate keys.</p>

<h3>Fourth Normal Form (4NF)</h3>
<p>Fourth Normal Form (4NF) requires that the table be in BCNF and that there be no multi-valued
dependencies.</p>

<h3>Fifth Normal Form (5NF)</h3>
<p>Fifth Normal Form (5NF) requires that the table be in 4NF and that there be no join dependencies
on any subset of the candidate key.</p>

<h3>Denormalization</h3>
<p>Denormalization is the process of adding redundant data to a database to improve read
performance.
This can involve adding redundant columns to a table or duplicating data in multiple tables.</p>

</div>
</div>

</div>
</div>


<div class="right-content-navigator rightnav">
<div class="navigator">
<a href="#" class="nav-link active">Indexes in SQL</a>
<a href="#" class="nav-link">Query Optimization Techniques</a>
<a href="#" class="nav-link">Normalization and Denormalization</a>
</div>
</div>


<script src="../js/script.js"></script>

</body>

</html>

0 comments on commit 5e9068d

Please sign in to comment.