Synonyms in SQL Server

A synonym in databases is an alternative name or alias for a table, view, sequence, or other schema items. They are mostly used to simplify access for users to database objects owned by other users.

Its purpose is to offer a different name for the base object, a different database item that may be present on a local or remote server.

To insulate a client application from alterations made to the base object’s name or location, an abstraction layer is provided.

Note that four-part names for function base objects are not supported.

Examples:
USE TestDatabase;
GO
CREATE SYNONYM Trxns
FOR TestDatabase.Trxns.tbTransactions;
GO

Without using the database name or the schema name, the data can be inserted into the base table, as shown below:

INSERT INTO Trxns (…..) VALUES (……);

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s