T-SQL: Synonym

Please see my other Database Development articles.

Simplifying T-SQL syntax.

Length T-SQL is unfortunately the byproduct of many business requirements in supporting an application.
As the parts of each statement grows (database.schema.object), so the overall length of the entire query.

Synonyms provide a painless method to drastically decrease code bloat in queries by allowing for an arbitrary name to be used in place of much longer statements. I will begin by right-clicking the “Synonyms” node in Object Explorer and chose to create a new one.

synonym-config

After entering the word I wish to replace a lengthy statement, in this case “sp” will replace “sales_people,” I now see my new synonym in the tree.

synonym-tree

With my synonym newly created I can begin to use it in place of the original statement.

synonym-codeAs you can see, the resultset is the same as when I use the original statement.

synonym-table

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