Home
SQL statements should not join too many tables
Rule description
- SQL statements 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 p INNER JOIN Purchasing.ProductVendor pv ON p.ProductID = pv.ProductID INNER JOIN Purchasing.Vendor v ON pv.BusinessEntityID = v.BusinessEntityID INNER JOIN Purchasing.Address 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 p, Purchasing.ProductVendor pv, Purchasing.Vendor v, Purchasing.Address ad Where p.ProductID = pv.ProductID AND pv.BusinessEntityID = v.BusinessEntityID AND ad.Id = v.BusinessEntityID ORDER BY p.Name, v.Name, ad.State;