Click or drag to resize

SA0252 : The referenced object (table, view, procedure or function) is in another database

The topic describes the SA0252 analysis rule.

Message

The referenced object (table, view, procedure or function) is in another database

Description

The rule checks for object references inside SELECT, UPDATE, DELETE, INSERT, MERGE and EXECUTE statements, which reside in a different than current database.

Instead of using hardcoded reference to an object in another database, in order to improve the maintainability of the code, create and use a synonym for external object reference.

e

Scope

The rule has a Batch scope and is applied only on the SQL script.

Parameters

Rule has no parameters.

Remarks

The rule requires Analysis Context. If context is missing, the rule will be skipped during analysis.

Categories

Design Rules, New Rules

Additional Information
Example Test Script
SQL
 1SELECT 
 2       *,Database1..Table4.Column1
 3FROM 
 4     ..Table1,
 5     Schema1.Table2, Database1..Table3
 6     INNER JOIN Database1..Table4   
 7        ON Database1..Table4.Column1=Database1..Table3.Column1 AND 
 8           Database1..Table4.Column2=Database1.Schema1.Table1.Column2
 9     INNER JOIN Database1.Schema2.Table4 ON 
10           Database1..Table2.Column1=Database1..UserDefinedFunction(1) AND 
11           Database1..Table2.Column2=Database1.Schema1.Table1.Column2
12WHERE 
13      Database1.Schema1.Table1.Column1=Database1.Schema1.Table2.Column1 AND 
14      Database1.Schema1.Table3.Column1=Database1.Schema1.Table2.Column3 
15EXECUTE database1.schema1.proc1
16EXECUTE adventureWorks2008r2_test.schema1.proc1

Analysis Results

 MessageLineColumn
1SA0252 : The referenced object Database1..Table3 is in another database.521
2SA0252 : The referenced object Database1..Table4 is in another database.616
3SA0252 : The referenced object Database1.Schema2.Table4 is in another database.916
4SA0252 : The referenced object database1.schema1.proc1 is in another database.158
See Also

Other Resources