Simplifying SQL Server 2005 development with synonyms

Source: Internet
Author: User
Tags sql

I. INTRODUCTION

If you have ever used SQL Server to develop any software, you will certainly be accustomed to using the four-part identifier to refer to an object:

  [[[server.][database].][schema_name].]object_name

As the square brackets above show, different parts of the syntax can be ignored, as long as you provide enough expression to identify your object without ambiguity. For example, all of the following expressions might refer to the same object:

  Server1.AdventureWorks.Production.ProductCategory
AdventureWorks.Production.ProductCategory
AdventureWorks..ProductCategory
ProductCategory

In most cases, you can use only three parts of the name and ignore the server name-unless you are dealing with objects on a connected server. By default, the context of all objects is a local database-your SQL statement executes in it. However, in some cases, or more accurately, you must use the entire four-part name (or a full qualified name). However, in SQL Server 2005, this situation has changed.

Two. Familiarity with synonyms

SQL Server 2005 introduces the concept of a synonym, which is a one-part name that can be replaced by a two or three-or four-part name in many SQL statements. Using synonyms allows you to reduce input and provide an abstraction layer to help you protect the underlying object's changes. To understand how this works, let's look at the syntax for creating synonyms first. The following is the syntax for the CREATE SYNONYM statement:

  CREATE SYNONYM [schema_name.]synonym_name FOR object_name

Here, object_name is the name of a SQL Server object that is sufficiently qualified to identify the object, and Synonym_name is the new name you want to assign to it. If you do not want to specify a pattern for synonyms, SQL Server uses the current user's default mode. When you create synonyms, the corresponding objects do not need to exist because the synonyms are late-bound: when you actually use synonyms, SQL Server simply checks the base object.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.