From 9a54941512f94d338267481592c3e45d02e91ac6 Mon Sep 17 00:00:00 2001 From: Konstantin Taranov Date: Fri, 7 Dec 2018 20:04:41 +0300 Subject: [PATCH] Add TOP using recommendation --- ...Server Name Convention and T-SQL Programming Style.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/SQL Server Name Convention and T-SQL Programming Style.md b/SQL Server Name Convention and T-SQL Programming Style.md index ef8ce23..8637a85 100644 --- a/SQL Server Name Convention and T-SQL Programming Style.md +++ b/SQL Server Name Convention and T-SQL Programming Style.md @@ -81,12 +81,13 @@ SQL Server TSQL Coding Conventions, Best Practices, and Programming Guidelines SELECT FirstName , LastName ``` - - Keywords and data types declaration should be in **UPPERCASE** - - `FROM, WHERE, INTO, JOIN, GROUP BY, ORDER BY` expressions should be aligned so, that all their arguments are placed under each other - - All objects must used with schema names but without database and server name: `FROM dbo.Table` - - All system database and tables must be in lower case for properly working in Case Sensitive instance + - Use `TOP` function with brackets because `TOP` has supports use of an expression, such as `(@Rows*2)`, or a subquery: `SELECT TOP(100) LastName …`. More details [here](https://www.red-gate.com/hub/product-learning/sql-prompt/sql-prompt-code-analysis-avoiding-old-style-top-clause). Also `TOP` without brackets does not work with `UPDATE` and `DELETE` statements. - For demo queries use TOP(100) or lower value because SQL Server SQL Server uses one sorting method for TOP 1-100 rows, and a different one for 101+ rows More details [here](https://www.brentozar.com/archive/2017/09/much-can-one-row-change-query-plan-part-2/) + - Keywords and data types declaration should be in **UPPERCASE** + - `FROM, WHERE, INTO, JOIN, GROUP BY, ORDER BY` expressions should be aligned so, that all their arguments are placed under each other (see Example below) + - All objects must used with schema names but without database and server name: `FROM dbo.Table` + - All system database and tables must be in lower case for properly working in Case Sensitive instance Example: