SR0010: Avoid using deprecated syntax when you join tables or views
RuleId | SR0010 |
Category | Microsoft.Design |
Breaking Change | Non-breaking |
To fix a violation in an inner join, use the INNER JOIN syntax, as the example later in this topic shows. For more information, see this page on the Microsoft Web site: Using Inner Joins.
To fix a violation in an outer join, use the appropriate OUTER JOIN syntax, as the examples later in this topic show. You have the following options:
LEFT OUTER JOIN or LEFT JOIN
RIGHT OUTER JOIN or RIGHT JOIN
NoteTransact-SQL supports FULL OUTER JOIN and FULL JOIN, but that type of join had no previous syntax.
For more information, see this page on the Microsoft Web site: Using Outer Joins.
The six examples demonstrate the following options:
Example 1 demonstrates the deprecated syntax for an inner join.
Example 2 demonstrates how you can update Example 1 to use current syntax.
Example 3 demonstrates the deprecated syntax for a left outer join.
Example 4 demonstrates how you can update Example 2 to use current syntax.
Example 5 demonstrates the deprecated syntax for a right outer join.
Example 6 demonstrates how you can update Example 5 to use current syntax.
-- Example 1: Deprecated syntax for an inner join SELECT [T2].[c3], [T1].[c3] FROM [dbo].[Table2] T2, [dbo].[Table1] T1 WHERE [T1].[ID] = [T2].[ID] -- Example 2: Current syntax for an inner join SELECT [T2].[c3], [T1].[c3] FROM [dbo].[Table2] AS T2 INNER JOIN [dbo].[Table1] as T1 ON [T2].[ID] = [T2].[ID] -- Example 3: Deprecated syntax for a left outer join SELECT [T2].[c3], [T1].[c3] FROM [dbo].[Table2] T2, [dbo].[Table1] T1 WHERE [T1].[ID] *= [T2].[ID] -- Example 4: Fixed syntax for a left outer join SELECT [T2].[c3], [T1].[c3] FROM [dbo].[Table2] AS T2 LEFT OUTER JOIN [dbo].[Table1] as T1 ON [T2].[ID] = [T2].[ID] -- Example 5: Deprecated syntax for a right outer join SELECT [T2].[c3], [T1].[c3] FROM [dbo].[Table2] T2, [dbo].[Table1] T1 WHERE [T1].[ID] =* [T2].[ID] -- Example 6: Fixed syntax for a right outer join SELECT [T2].[c3], [T1].[c3] FROM [dbo].[Table2] AS T2 RIGHT OUTER JOIN [dbo].[Table1] as T1 ON [T2].[ID] = [T2].[ID]