SQL Interview: 36 Dereferencing server names in T-SQL code

SQL Interview: 36 Dereferencing server names in T-SQL code

This is a post in the SQL Interview series. These aren’t trick or gotcha questions, they’re just questions designed to scope out a candidate’s knowledge around SQL Server and Azure SQL Database.

Section: Administration Level: Medium

Question:

You are using linked servers to refer to tables in a database on another server.

You are concerned that the name of the server appears in three-part table names throughout your code. If the linked server name changes, it would be very messy to locate and correct all references to it.

How can you avoid this?

Answer:

Create synonyms to refer to any of the remote tables or views.

Ideally, create the synonyms in a separate schema where the name of the schema relates to the purpose of the reference, rather than the server name.

If the name of the linked server changes, only the synonyms would need updating.

2025-04-13