Advantages and disadvantages of using synonyms in SQL Server 2005

Source: Internet
Author: User
Tags new features

Questions raised

In my new job, I faced the problem of archiving the tables that were created in the product database, because as the database grows, it needs to be moved now. At the same time, these archived tables are used for several tasks and are invoked in the application's code. Moving them in this way is a very complicated process. I want to find a way to minimize the amount of work that developers have to do, because they have very limited time. Can you tell me the best way to file the table in a limited time?

Expert answers

There is a feature in SQL Server 2005 that solves this problem and provides further optimizations and tool devices, which are synonyms in SQL Server 2005 (synonyms). Synonyms (synonym) are new features in SQL Server 2005. It is an alias that is given in an existing or potential new object. It's just a pointer or parameter, so it's not treated as an object.

In order to create a synonym (synonym), you need to have the right to create synonyms (synonym). If you are a system administrator or db_owner, you will have these permissions and can grant this permission to other users. In addition, if you need to create a synonym that spans a database, you need the permissions of another database.

The following is an example of creating a synonym (synonym) in a database and referencing another object in the database:

USE AdventureWorks
GO
CREATE SYNONYM MySyn FOR Production.Location
GO

To check these tasks, you can use the following query in the use of synonym:

SELECT * From MySyn

Here is another example of creating a synonym (synonym) in a database and referencing the object in another database:

USE master
GO
CREATE SYNONYM dbo.MySyn FOR AdventureWorks.Production.Location
GO

To get all the changes in the synonym (synonyms), you can use the following command:

SELECT * FROM sysobjects
WHERE xtype = 'SN'
ORDER BY NAME

Delete synonyms (synonym) you can use the following command:

USE AdventureWorks;
GO
DROP SYNONYM MySyn
GO

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.