July 7, 2021, 8:34 p.m.
In development, writing the queries is not just important. It is also important to write efficient SQL queries. Efficient queries give faster results. When the SQL queries are optimized your application's faster performance saves a lot of time.
1) Use the exact number of columns
2) No need to count everything in the table
3) Avoid using DISTINCT keyword.
4) Create a small batches of Data for Deletion and Updation
5) Use Temp Tables
In development, writing the queries is not just important. It is also important to write efficient SQL queries. Efficient queries give faster results. When the SQL queries are optimized your application's faster performance saves a lot of time.
1) Use the exact number of columns
2) No need to count everything in the table
3) Avoid using DISTINCT keyword.
4) Create a small batches of Data for Deletion and Updation
5) Use Temp Tables
1) Use the exact number of columns: While writing the select statement, make sure that you're writing the correct number of columns against as many rows as you want. This will make your query faster, and you will speed your processes.
2) No need to count everything in the table: To check the existence of some data, you need to carry out an action.
SELECT 1 FROM table_name;
Do not use SELECT count(*) FROM table_name;
3) Avoid using DISTINCT keyword: You should always try to avoid using the DISTINCT keyword. Using this keyword requires an extra operation. This will slow down all the queries and make it almost impossible to get what you need.
4) Create a small batches of Data for Deletion and Updation: Instead of deleting and updating data in bulk create small batches of them. In case if there will be a rollback, you will avoid losing or killing your data. It also enhances concurrency, because the data you except the part you're deleting or updating continue doing other work.
5) Use Temp Tables: Temporary tables are used in many situations, such as joining a small table to a larger one. You can improve data performance by extracting data from the large table, and then transferring it to a temp table then join with that. This reduces the power required in processing.
Good Job.