Home

Lines should not be too long

Description

    The "Lines should not be too long" code rule for SQL Server states that lines of code should not exceed 80 characters in length. This is to ensure that the code is easier to read and understand. Longer lines can make it difficult to read and understand the code, and can also make it difficult to debug or modify the code. By limiting the length of lines, code is more manageable and easier to work with.

Key Benefits

  • Easier to read: Lines should not be too long, as this makes it difficult to read and understand the text.
  • Better comprehension: Shorter lines allow readers to focus on one concept at a time, leading to better comprehension of the material.
  • Easier to edit: Longer lines can be difficult to edit, as the text can become jumbled and confusing. Keeping lines short makes it easier to make changes to the text.
  • More organized: Short lines create a more organized appearance, making the text easier to scan and understand.

 

Non-compliant Code Example

SELECT ProductID, ProductName, ProductCategory, Price, InStockQuantity, AVG(OrderQty) AS AverageQuantity, SUM(LineTotal) AS Total  --Non compliant code (Line length is more then default defined limit 100)
FROM Sales.SalesOrderDetail
GROUP BY ProductID
HAVING SUM(LineTotal) > 3000.00
AND AVG(OrderQty) < 3;

Compliant Code Example

SELECT ProductID, ProductName,  --Compliant code (Line length is less then default defined limit 100)
 ProductCategory,
 Price,
 InStockQuantity,
 AVG(OrderQty) AS AverageQuantity,
 SUM(LineTotal) AS Total
FROM Sales.SalesOrderDetail
GROUP BY ProductID
HAVING SUM(LineTotal) > 3000.00
AND AVG(OrderQty) < 3;
Visual Expert 2024
 VETSQLRULE76