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

The topic describes the SA0252 analysis rule.


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


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

How to fix

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.


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


Rule has no parameters.


The rule requires SQL Connection. If there is no connection provided, the rule will be skipped during analysis.

Effort To Fix
20 minutes per issue.

Design Rules, Bugs

Additional Information
Example Test SQL
 2       *,Database1..Table4.Column1
 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
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
  Message Line Column
1 SA0252 : The referenced object Database1..Table3 is in another database. 5 21
2 SA0252 : The referenced object Database1..Table4 is in another database. 6 16
3 SA0252 : The referenced object Database1.Schema2.Table4 is in another database. 9 16
4 SA0252 : The referenced object database1.schema1.proc1 is in another database. 15 8
See Also

Other Resources