Home

Queries should not join too many tables

Rule description

  • Queries should not join too many tables

 

Non-compliant Code Example

SELECT p.Name AS ProductName, v.Name AS VendorName, ad.State  --Non compliant code (Join tables are more then default defined limit 3)
FROM Production.Product AS p   
INNER JOIN Purchasing.ProductVendor AS pv ON p.ProductID = pv.ProductID  
INNER JOIN Purchasing.Vendor AS v ON pv.BusinessEntityID = v.BusinessEntityID  
INNER JOIN Purchasing.Address AS ad ON ad.Id = v.BusinessEntityID  
ORDER BY p.Name, v.Name, ad.State
SELECT p.Name AS ProductName, v.Name AS VendorName, ad.State   --Non compliant code (Join tables are more then default defined limit 3)
FROM Production.Product AS p, Purchasing.ProductVendor AS pv,  Purchasing.Vendor AS v, Purchasing.Address AS ad 
Where p.ProductID = pv.ProductID  
AND pv.BusinessEntityID = v.BusinessEntityID  
AND ad.Id = v.BusinessEntityID  
ORDER BY p.Name, v.Name, ad.State ;
Visual Expert 2020
 VETSQLRULE34