Query optimization tips. Query optimizations tips: - Always use a WHERE clause to restrict the number of returned queries. - Only return the needed columns and rows that are needed by a query. Be wise of these while writing any query. - Use views and stored procedures efficiently instead of complex queries. - Avoid use of cursors wherever possible. - Use SELECT rows FROM sysindexes WHERE id = OBJECT_ID('table_name') instead of SELECT COUNT(*) to know the number of rows returned. - Use constraints instead of triggers when applicable. - Use table variables efficiently. - Avoid use of HAVING and DISTINCT clause. - Use UINION ALL instead of UNION wherever possible. - Do not use optimizer hints in queries.Query optimization tips. - Use indexes. - Specify only the columns necessary while using select query. - If join queries are used, indexes that match the join column must be used.
|