Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2d829e1

Browse files
Merge pull request #378 from EmergentSoftware/dev
Wiki changes
2 parents 0a8134b + 64bb414 commit 2d829e1

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

‎docs/findings/SQLCodeDevelopment.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -483,18 +483,24 @@ WHILE EXISTS (SELECT * FROM #Person WHERE IsProcessedFlag = 0)
483483

484484
Use Temporary Tables and not Table Variables.
485485

486-
- There is optimization limitation like lack of statistics that very frequently lead to performance issues. The advice of "use table variables if you have less than NNN rows" is flawed. It might seem like temporary tables are performant, but they are not scalable with a couple more years of data.
486+
- There is optimization limitations like lack of statistics that very frequently lead to performance issues. The advice of "use table variables if you have less than NNN rows" is flawed. It might seem like temporary tables are performant, but they are not scalable with a couple more years of data.
487487
- There are two use cases for table variable and are infrequently called for.
488488
1. Extremely highly called code where recompiles from temporary table activity is a problem
489489
2. Audit scenarios when you need to keep data after a transaction is rolled back.
490490

491-
```sql
491+
**Instead Of:**
492+
493+
``` sql
492494
CREATE TABLE #UseMe (
493495
UseMeId int NOT NULL IDENTITY(1, 1) PRIMARY KEY
494496
,FirstName nvarchar(100) NOT NULL
495497
,LastName nvarchar(100) NOT NULL
496498
);
499+
```
497500

501+
**Do This:**
502+
503+
``` sql
498504
DECLARE @DoNotUseMe table (
499505
DoNotUseMeId int NOT NULL IDENTITY(1, 1) PRIMARY KEY
500506
,FirstName nvarchar(100) NOT NULL
@@ -614,7 +620,7 @@ aka. Catch-All Query or Kitchen Sink Query
614620

615621
If your stored procedure has multiple parameters where any one (or more) number are parameters are optional, you have a dynamic search query.
616622

617-
If your query is moderately complex you should use `OPTION (RECOMPILE)`. If you query is complex you should build the query with dynamic SQL.
623+
If your query is moderately complex you should use `OPTION (RECOMPILE)`. If your query is complex, you should build the query with dynamic SQL.
618624

619625
You will also know this based on the `WHERE` clause of the query. You will see `@ProductId IS NULL` or have parameters wrapped in an `ISNULL()`.
620626

@@ -973,12 +979,10 @@ END CATCH; /* <-- semicolon goes at the end here */
973979

974980
---
975981

976-
<a name="100"/>
977-
978982
## Using a Non-SARGable Expression in a WHERE Clause
979983
**Check Id:** 100 [Not implemented yet. Click here to add the issue if you want to develop and create a pull request.](https://github.com/EmergentSoftware/SQL-Server-Development-Assessment/issues/new?assignees=&labels=enhancement&template=feature_request.md&title=Using+a+Non-SARGable+Expression+in+a+WHERE+Clause)
980984

981-
Search ARGument..able. Avoid having a column or variable used within an expression or used as a function parameter. Columns are best used its self on one side of the operator. You will get a table scan instead of a index seek which will hurt performance.
985+
Search ARGument..able. Avoid having a column or variable used within an expression or used as a function parameter. You will get a table scan instead of an index seek which will hurt performance.
982986

983987
![Non-SARGable Scan vs. SARGable Seek](../Images/Using_a_Non-SARGable_Expression_in_a_WHERE_Clause.png)
984988

@@ -987,7 +991,7 @@ Another issue with non-sargable queries besides the forced table scan is SQL Ser
987991

988992
- See [Using Missing Indexes Recommendations](/SQL-Server-Development-Assessment/best-practices-and-potential-findings/sql-code-conventions#using-missing-indexes-recommendations)
989993

990-
By changed the WHERE clause to not use the YEAR() function and doing a bit more typing allows SQL Server to understand what you want it to do.
994+
Changing the WHERE clause to not use the YEAR() function and doing a bit more typing allows SQL Server to understand what you want it to do.
991995

992996
![Non-SARGable Does Not Get Index Recommendation](../Images/Non-SARGable_Does_Not_Get_Index_Recommendation.png)
993997

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /