SlideShare une entreprise Scribd logo
1  sur  16
Télécharger pour lire hors ligne
Database Optimization Tips




                    Nikhildas.P.C
                    nikhildasp@gmail.com
Topics

1.   Transact – SQL optimization tips
2.   SQL Server optimization tips
1. Transact – SQL optimization tips

1.   Try to restrict the queries result set by
     using the WHERE clause.
2.   Try to restrict the queries result set by
     returning only the particular columns
     from the table, not all table’s columns.
3.   Use views and stored procedures
     instead of heavy-duty queries.
4.   Try to avoid using SQL Server cursors,
     whenever possible.
5.   If you need to return the total table’s
     row count, you can use alternative way
     instead of SELECT COUNT(*) statement.
1. Transact – SQL optimization tips

1.   Use table variables instead of temporary
     tables.
2.   Try to avoid the HAVING clause,
     whenever possible.
3.   Try to avoid using the DISTINCT clause,
     whenever possible.
4.   Include SET NOCOUNT ON statement
     into your stored procedures to stop the
     message indicating the number of rows
     affected by a T-SQL statement.
1. Transact – SQL optimization tips

1.   Use the select statements with TOP
     keyword or the SET ROWCOUNT
     statement, if you need to return only
     the first n rows.
2.   Use the FAST number_rows table hint if
     you need to quickly return
     ‘number_rows’ rows.
3.   Try to use UNION ALL statement instead
     of UNION, whenever possible.
4.   Do not use optimizer hints in your
     queries.
1. Transact – SQL optimization tips

1.   Try to avoid using DDL (Data Definition
     Language) statements inside your
     stored procedure.
2.   If you have a very large stored
     procedure, try to break down this stored
     procedure into several sub-procedures,
     and call them from a controlling stored
     procedure.
3.   Use the sp_executesql stored procedure
     instead of the EXECUTE statement.
4.   Try to use constraints instead of
     triggers, whenever possible.
1. Transact – SQL optimization tips

1.   Don’t use the prefix “sp_” in the stored
     procedure name if you need to create a
     stored procedure to run in a database
     other than the master database.
2.   Consider returning the integer value as
     an RETURN statement instead of an
     integer value as part of a recordset.
3.   Call stored procedure using its fully
     qualified name.
4.   Try to avoid using temporary tables
     inside your stored procedure.
1. Transact – SQL optimization tips

1.   Include the SET ANSI_WARNINGS ON,
     SET ANSI_NULLS ON statement into
     your stored procedures.
2.   Always add an Debug parameter to your
     stored procedures. This can be a BIT
     data type.
3.   If your stored procedure always returns
     a single row resultset, consider
     returning the resultset using OUTPUT
     parameters instead of a SELECT
     statement
1. Transact – SQL optimization tips
1.   Use Alias name with Column Name in
     select statement.
2.   Use appropriate Join (Inner,Outer,Self)
3.   Use Where condition before Joining (Eg.
     Select D.CustName from ( select ID
     from CustMaster where CustID = 12346
     ) M Inner Join CustDetails D on M.ID =
     D.ID
4.   Use Between instead of >= <=, if
     possible
5.   Use Order by,where,join For Indexed
     Column.
6.   Avoid functions with WHERE clause.
1. Transact – SQL optimization tips
1.   Do not use column numbers in the
     ORDER BY clause - Eg. Order by 2
2.   ANSI-Standard Join clauses instead of
     the old style joins.
3.   Do not call functions repeatedly within
     your stored procedures, triggers,
     functions and batches.(Eg. Len (Name)
     call the LEN function once, and store the
     result in a variable for later use.)
4.   If you need to delete all tables rows,
     consider using TRUNCATE TABLE
     instead of DELETE command.
1. Transact – SQL optimization tips
1.   Do not let your front-end applications
     query/manipulate the data directly
     using SELECT or INSERT/UPDATE /
     DELETE statements. Instead, create
     stored procedures and let your
     applications access these stored
     procedures.
2.   Use the graphical execution plan in
     Query Analyzer or SHOWPLAN_TEXT or
     SHOWPLAN_ALL commands to analyze
     your queries. Make sure your queries do
     an "Index seek" instead of an "Index
     scan" or a "Table scan."
1. Transact – SQL optimization tips
1.   Don't Compare null value with =,<>
     (Eg.IF @DDate <> NULL) Use – IF
     @Ddate Is Null
2.   A Table should have
     . primary key
     . minimum of one clustered index
     . appropriate amount of non-clustered
     index
     . Non-clustered index should be created
     on columns of table based on query
     which is running
1. Transact – SQL optimization tips
1.   Following priority order should be
     followed when any index is created a)
     WHERE clause, b) JOIN clause, c)
     ORDER BY clause, d) SELECT clause.
2.   Check if there is at least 30% HHD is
     empty – it improves the performance a
     bit.
3.   Use Error Tracing in SP,Fn,trigger (Eg.
     Try Catch or @@ERROR global variable)
4.   Use BEGIN TRANSACTION, COMMIT
     TRANSACTION and ROLLBACK
     TRANSACTION.
1. Transact – SQL optimization tips
1.   Avoid using dynamic SQL statements
     inside stored procedures, i.e., Do not
     use SQL statements to create SQL
     statements.
2.   Be careful while SELECT-ing strings with
     LIKE clause. If it is not used wisely, it
     will give rise to performance problems.
3.   Use Update Statistics with bulk
     insertion, deletion query.
4.   Use Covering indexes.
1. Transact – SQL optimization tips
1.   Use indexed Views.
2.    Use Apply clause, if Possible
3.   Use Computed Column
4.   Use Profiler,Database engine Tuning
     advisor,Execution plan to monitor
     performance.
5.   Try to write code neatly with proper
     commenting and program flow picture.
THANKS

Contenu connexe

Tendances

Twp Upgrading 10g To 11g What To Expect From Optimizer
Twp Upgrading 10g To 11g What To Expect From OptimizerTwp Upgrading 10g To 11g What To Expect From Optimizer
Twp Upgrading 10g To 11g What To Expect From Optimizerqiw
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for BeginnersAbdelhay Shafi
 
Sql select statement
Sql select statementSql select statement
Sql select statementVivek Singh
 
Sql scripting sorcerypaper
Sql scripting sorcerypaperSql scripting sorcerypaper
Sql scripting sorcerypaperoracle documents
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-dbuncleRhyme
 
Clase 13 integridad modificada
Clase 13 integridad   modificadaClase 13 integridad   modificada
Clase 13 integridad modificadaTitiushko Jazz
 
Sql server ___________session_19(triggers)
Sql server  ___________session_19(triggers)Sql server  ___________session_19(triggers)
Sql server ___________session_19(triggers)Ehtisham Ali
 
Procedures and triggers in SQL
Procedures and triggers in SQLProcedures and triggers in SQL
Procedures and triggers in SQLVikash Sharma
 
Part36 parameter,form success
Part36 parameter,form successPart36 parameter,form success
Part36 parameter,form successGirija Muscut
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007paulguerin
 

Tendances (17)

Twp Upgrading 10g To 11g What To Expect From Optimizer
Twp Upgrading 10g To 11g What To Expect From OptimizerTwp Upgrading 10g To 11g What To Expect From Optimizer
Twp Upgrading 10g To 11g What To Expect From Optimizer
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
 
Sql select statement
Sql select statementSql select statement
Sql select statement
 
Db function
Db functionDb function
Db function
 
Lab5 sub query
Lab5   sub queryLab5   sub query
Lab5 sub query
 
Sql scripting sorcerypaper
Sql scripting sorcerypaperSql scripting sorcerypaper
Sql scripting sorcerypaper
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-db
 
Review of SQL
Review of SQLReview of SQL
Review of SQL
 
Clase 13 integridad modificada
Clase 13 integridad   modificadaClase 13 integridad   modificada
Clase 13 integridad modificada
 
Sql server ___________session_19(triggers)
Sql server  ___________session_19(triggers)Sql server  ___________session_19(triggers)
Sql server ___________session_19(triggers)
 
Procedures and triggers in SQL
Procedures and triggers in SQLProcedures and triggers in SQL
Procedures and triggers in SQL
 
Data integrity
Data integrityData integrity
Data integrity
 
Les18
Les18Les18
Les18
 
It6312 dbms lab-ex2
It6312 dbms lab-ex2It6312 dbms lab-ex2
It6312 dbms lab-ex2
 
Lab1 select statement
Lab1 select statementLab1 select statement
Lab1 select statement
 
Part36 parameter,form success
Part36 parameter,form successPart36 parameter,form success
Part36 parameter,form success
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
 

En vedette

MS SQL SERVER: Creating Views
MS SQL SERVER: Creating ViewsMS SQL SERVER: Creating Views
MS SQL SERVER: Creating Viewssqlserver content
 
Using grouping sets in sql server 2008 tech republic
Using grouping sets in sql server 2008   tech republicUsing grouping sets in sql server 2008   tech republic
Using grouping sets in sql server 2008 tech republicKaing Menglieng
 
Consultas en MS SQL Server 2012
Consultas en MS SQL Server 2012Consultas en MS SQL Server 2012
Consultas en MS SQL Server 2012CarlosFloresRoman
 
Sql tuning guideline
Sql tuning guidelineSql tuning guideline
Sql tuning guidelineSidney Chen
 
e computer notes - Subqueries
e computer notes - Subqueriese computer notes - Subqueries
e computer notes - Subqueriesecomputernotes
 
Sub-queries,Groupby and having in SQL
Sub-queries,Groupby and having in SQLSub-queries,Groupby and having in SQL
Sub-queries,Groupby and having in SQLVikash Sharma
 
Triggers-Sequences-SQL
Triggers-Sequences-SQLTriggers-Sequences-SQL
Triggers-Sequences-SQLPatrick Seery
 
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1 "Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1 Andriy Krayniy
 
Lecture 4. MS SQL. DML Triggers
Lecture 4. MS SQL. DML TriggersLecture 4. MS SQL. DML Triggers
Lecture 4. MS SQL. DML TriggersAlexey Furmanov
 
Sql query analyzer & maintenance
Sql query analyzer & maintenanceSql query analyzer & maintenance
Sql query analyzer & maintenancenspyrenet
 
SQL Server - Using Tools to Analyze Query Performance
SQL Server - Using Tools to Analyze Query PerformanceSQL Server - Using Tools to Analyze Query Performance
SQL Server - Using Tools to Analyze Query PerformanceMarek Maśko
 
View, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - ThaiptView, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - ThaiptFramgia Vietnam
 
Database Transactions and SQL Server Concurrency
Database Transactions and SQL Server ConcurrencyDatabase Transactions and SQL Server Concurrency
Database Transactions and SQL Server ConcurrencyBoris Hristov
 
Data Compression In SQL
Data Compression In SQLData Compression In SQL
Data Compression In SQLBoosh Booshan
 

En vedette (20)

MS SQL SERVER: Creating Views
MS SQL SERVER: Creating ViewsMS SQL SERVER: Creating Views
MS SQL SERVER: Creating Views
 
Joins SQL Server
Joins SQL ServerJoins SQL Server
Joins SQL Server
 
Using grouping sets in sql server 2008 tech republic
Using grouping sets in sql server 2008   tech republicUsing grouping sets in sql server 2008   tech republic
Using grouping sets in sql server 2008 tech republic
 
Consultas en MS SQL Server 2012
Consultas en MS SQL Server 2012Consultas en MS SQL Server 2012
Consultas en MS SQL Server 2012
 
Sql tuning guideline
Sql tuning guidelineSql tuning guideline
Sql tuning guideline
 
Sql xp 04
Sql xp 04Sql xp 04
Sql xp 04
 
Statistics
StatisticsStatistics
Statistics
 
e computer notes - Subqueries
e computer notes - Subqueriese computer notes - Subqueries
e computer notes - Subqueries
 
Sub-queries,Groupby and having in SQL
Sub-queries,Groupby and having in SQLSub-queries,Groupby and having in SQL
Sub-queries,Groupby and having in SQL
 
Locking in SQL Server
Locking in SQL ServerLocking in SQL Server
Locking in SQL Server
 
Triggers-Sequences-SQL
Triggers-Sequences-SQLTriggers-Sequences-SQL
Triggers-Sequences-SQL
 
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1 "Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
 
Lecture 4. MS SQL. DML Triggers
Lecture 4. MS SQL. DML TriggersLecture 4. MS SQL. DML Triggers
Lecture 4. MS SQL. DML Triggers
 
Locking And Concurrency
Locking And ConcurrencyLocking And Concurrency
Locking And Concurrency
 
Sql query analyzer & maintenance
Sql query analyzer & maintenanceSql query analyzer & maintenance
Sql query analyzer & maintenance
 
SQL Server - Using Tools to Analyze Query Performance
SQL Server - Using Tools to Analyze Query PerformanceSQL Server - Using Tools to Analyze Query Performance
SQL Server - Using Tools to Analyze Query Performance
 
View, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - ThaiptView, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - Thaipt
 
SQL subquery
SQL subquerySQL subquery
SQL subquery
 
Database Transactions and SQL Server Concurrency
Database Transactions and SQL Server ConcurrencyDatabase Transactions and SQL Server Concurrency
Database Transactions and SQL Server Concurrency
 
Data Compression In SQL
Data Compression In SQLData Compression In SQL
Data Compression In SQL
 

Similaire à Sql db optimization

Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standardsAlessandro Baratella
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsNirav Shah
 
Sql coding-standard-sqlserver
Sql coding-standard-sqlserverSql coding-standard-sqlserver
Sql coding-standard-sqlserverlochaaaa
 
Basics on SQL queries
Basics on SQL queriesBasics on SQL queries
Basics on SQL queriesKnoldus Inc.
 
Mohan Testing
Mohan TestingMohan Testing
Mohan Testingsmittal81
 
Oracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practicesOracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practicesSmitha Padmanabhan
 
Optimized cluster index generation
Optimized cluster index generationOptimized cluster index generation
Optimized cluster index generationRutvik Pensionwar
 
Stored procedure tuning and optimization t sql
Stored procedure tuning and optimization t sqlStored procedure tuning and optimization t sql
Stored procedure tuning and optimization t sqlnishantdavid9
 
Guide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution PlanGuide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution PlanOptimiz DBA
 
SQL Server 2008 Performance Enhancements
SQL Server 2008 Performance EnhancementsSQL Server 2008 Performance Enhancements
SQL Server 2008 Performance Enhancementsinfusiondev
 
Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager Krishan Singh
 
Performance tuning
Performance tuningPerformance tuning
Performance tuningami111
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-onlyAshwin Kumar
 
TSQL Coding Guidelines
TSQL Coding GuidelinesTSQL Coding Guidelines
TSQL Coding GuidelinesChris Adkin
 

Similaire à Sql db optimization (20)

Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standards
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tips
 
Sql coding-standard-sqlserver
Sql coding-standard-sqlserverSql coding-standard-sqlserver
Sql coding-standard-sqlserver
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
 
Basics on SQL queries
Basics on SQL queriesBasics on SQL queries
Basics on SQL queries
 
Mohan Testing
Mohan TestingMohan Testing
Mohan Testing
 
Teradata sql-tuning-top-10
Teradata sql-tuning-top-10Teradata sql-tuning-top-10
Teradata sql-tuning-top-10
 
Mysql Optimization
Mysql OptimizationMysql Optimization
Mysql Optimization
 
Oracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practicesOracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practices
 
Optimized cluster index generation
Optimized cluster index generationOptimized cluster index generation
Optimized cluster index generation
 
Stored procedure tuning and optimization t sql
Stored procedure tuning and optimization t sqlStored procedure tuning and optimization t sql
Stored procedure tuning and optimization t sql
 
PLSQL Practices
PLSQL PracticesPLSQL Practices
PLSQL Practices
 
Guide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution PlanGuide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution Plan
 
PLSQL Advanced
PLSQL AdvancedPLSQL Advanced
PLSQL Advanced
 
SQL Server 2008 Performance Enhancements
SQL Server 2008 Performance EnhancementsSQL Server 2008 Performance Enhancements
SQL Server 2008 Performance Enhancements
 
Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager
 
Performance tuning
Performance tuningPerformance tuning
Performance tuning
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
 
Stored procedure tunning
Stored procedure tunningStored procedure tunning
Stored procedure tunning
 
TSQL Coding Guidelines
TSQL Coding GuidelinesTSQL Coding Guidelines
TSQL Coding Guidelines
 

Dernier

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 

Dernier (20)

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 

Sql db optimization

  • 1. Database Optimization Tips Nikhildas.P.C nikhildasp@gmail.com
  • 2. Topics 1. Transact – SQL optimization tips 2. SQL Server optimization tips
  • 3. 1. Transact – SQL optimization tips 1. Try to restrict the queries result set by using the WHERE clause. 2. Try to restrict the queries result set by returning only the particular columns from the table, not all table’s columns. 3. Use views and stored procedures instead of heavy-duty queries. 4. Try to avoid using SQL Server cursors, whenever possible. 5. If you need to return the total table’s row count, you can use alternative way instead of SELECT COUNT(*) statement.
  • 4. 1. Transact – SQL optimization tips 1. Use table variables instead of temporary tables. 2. Try to avoid the HAVING clause, whenever possible. 3. Try to avoid using the DISTINCT clause, whenever possible. 4. Include SET NOCOUNT ON statement into your stored procedures to stop the message indicating the number of rows affected by a T-SQL statement.
  • 5. 1. Transact – SQL optimization tips 1. Use the select statements with TOP keyword or the SET ROWCOUNT statement, if you need to return only the first n rows. 2. Use the FAST number_rows table hint if you need to quickly return ‘number_rows’ rows. 3. Try to use UNION ALL statement instead of UNION, whenever possible. 4. Do not use optimizer hints in your queries.
  • 6. 1. Transact – SQL optimization tips 1. Try to avoid using DDL (Data Definition Language) statements inside your stored procedure. 2. If you have a very large stored procedure, try to break down this stored procedure into several sub-procedures, and call them from a controlling stored procedure. 3. Use the sp_executesql stored procedure instead of the EXECUTE statement. 4. Try to use constraints instead of triggers, whenever possible.
  • 7. 1. Transact – SQL optimization tips 1. Don’t use the prefix “sp_” in the stored procedure name if you need to create a stored procedure to run in a database other than the master database. 2. Consider returning the integer value as an RETURN statement instead of an integer value as part of a recordset. 3. Call stored procedure using its fully qualified name. 4. Try to avoid using temporary tables inside your stored procedure.
  • 8. 1. Transact – SQL optimization tips 1. Include the SET ANSI_WARNINGS ON, SET ANSI_NULLS ON statement into your stored procedures. 2. Always add an Debug parameter to your stored procedures. This can be a BIT data type. 3. If your stored procedure always returns a single row resultset, consider returning the resultset using OUTPUT parameters instead of a SELECT statement
  • 9. 1. Transact – SQL optimization tips 1. Use Alias name with Column Name in select statement. 2. Use appropriate Join (Inner,Outer,Self) 3. Use Where condition before Joining (Eg. Select D.CustName from ( select ID from CustMaster where CustID = 12346 ) M Inner Join CustDetails D on M.ID = D.ID 4. Use Between instead of >= <=, if possible 5. Use Order by,where,join For Indexed Column. 6. Avoid functions with WHERE clause.
  • 10. 1. Transact – SQL optimization tips 1. Do not use column numbers in the ORDER BY clause - Eg. Order by 2 2. ANSI-Standard Join clauses instead of the old style joins. 3. Do not call functions repeatedly within your stored procedures, triggers, functions and batches.(Eg. Len (Name) call the LEN function once, and store the result in a variable for later use.) 4. If you need to delete all tables rows, consider using TRUNCATE TABLE instead of DELETE command.
  • 11. 1. Transact – SQL optimization tips 1. Do not let your front-end applications query/manipulate the data directly using SELECT or INSERT/UPDATE / DELETE statements. Instead, create stored procedures and let your applications access these stored procedures. 2. Use the graphical execution plan in Query Analyzer or SHOWPLAN_TEXT or SHOWPLAN_ALL commands to analyze your queries. Make sure your queries do an "Index seek" instead of an "Index scan" or a "Table scan."
  • 12. 1. Transact – SQL optimization tips 1. Don't Compare null value with =,<> (Eg.IF @DDate <> NULL) Use – IF @Ddate Is Null 2. A Table should have . primary key . minimum of one clustered index . appropriate amount of non-clustered index . Non-clustered index should be created on columns of table based on query which is running
  • 13. 1. Transact – SQL optimization tips 1. Following priority order should be followed when any index is created a) WHERE clause, b) JOIN clause, c) ORDER BY clause, d) SELECT clause. 2. Check if there is at least 30% HHD is empty – it improves the performance a bit. 3. Use Error Tracing in SP,Fn,trigger (Eg. Try Catch or @@ERROR global variable) 4. Use BEGIN TRANSACTION, COMMIT TRANSACTION and ROLLBACK TRANSACTION.
  • 14. 1. Transact – SQL optimization tips 1. Avoid using dynamic SQL statements inside stored procedures, i.e., Do not use SQL statements to create SQL statements. 2. Be careful while SELECT-ing strings with LIKE clause. If it is not used wisely, it will give rise to performance problems. 3. Use Update Statistics with bulk insertion, deletion query. 4. Use Covering indexes.
  • 15. 1. Transact – SQL optimization tips 1. Use indexed Views. 2. Use Apply clause, if Possible 3. Use Computed Column 4. Use Profiler,Database engine Tuning advisor,Execution plan to monitor performance. 5. Try to write code neatly with proper commenting and program flow picture.