SQL 中同义词的优点?

发布于 2024-10-23 17:57:47 字数 36 浏览 0 评论 0原文

为什么使用同义词? SQL 中 syNONYMS 的优点?

why synonyms are used?,advantages of syNONYMS IN SQL?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱殇璃 2024-10-30 17:57:47

它们只是数据库内对象的简写名称。例如,如果数据库中有名为 ProductionControl.Inventory.Products 的命名空间表,则可以创建名为 Products 的同义词。它们还可以方便地控制存储过程中对其他数据库的命名访问。如果您有引用其他数据库中的表的 SP,则创建同义词并使用它可以为您提供更多控制,以防同义词的目标发生更改。这在以下场景中非常有用:您有引用开发数据库的 SP,但部署到生产时名称不同。所以你只需更新同义词就可以了。

They're just shorthand names for objects inside a database. For example, you can create a synonym called Products if you have a namespace'd table in a database called ProductionControl.Inventory.Products. They're also handy for controlling named access to other databases in stored procedures. If you have SPs that refer to tables in other databases, creating a synonym and using that instead gives you more control in case the target of the synonym ever changes. This is useful in scenarios where you have SPs that refer to a development database, but when you deploy to production the name is different. So you'd just update the synonym and you'd be OK.

々眼睛长脚气 2024-10-30 17:57:47

来自 MSDN 了解同义词

同义词是一个数据库对象,它
服务于以下目的:

  • 为另一个数据库对象提供替代名称,称为
    作为基础对象,可以存在于
    本地或远程服务器。

  • 提供保护客户端应用程序的抽象层
    更改姓名或
    基础对象的位置。

From MSDN Understanding Synonyms

A synonym is a database object that
serves the following purposes:

  • Provides an alternative name for another database object, referred to
    as the base object, that can exist on
    a local or remote server.

  • Provides a layer of abstraction that protects a client application
    from changes made to the name or
    location of the base object.

我的黑色迷你裙 2024-10-30 17:57:47

在某些企业系统中,您可能必须处理您无法控制的远程对象。例如,由其他部门或团队维护的数据库。

同义词可以帮助您将基础对象的名称和位置与 SQL 代码解耦。这样,即使您想要的表被移动到新的服务器/数据库或重命名,您也可以针对同义词表进行编码。

例如,我可以编写这样的查询:

insert into MyTable
(...)
select ... 
from remoteServer.remoteDatabase.dbo.Employee

但是如果服务器、数据库、模式或表发生更改,则会影响我的代码。相反,我可以为远程服务器创建一个同义词并使用该同义词:

insert into MyTable
(...)
select ... 
from EmployeeSynonym

如果底层对象更改位置或名称,我只需更新同义词以指向新对象。

http: //www.mssqltips.com/sqlservertip/1820/use-synonyms-to-abstract-the-location-of-sql-server-database-objects/

In some enterprise systems, you may have to deal with remote objects over which you have no control. For example, a database that is maintained by another department or team.

Synonyms can help you decouple the name and location of the underlying object from your SQL code. That way you can code against a synonym table even if the table you want is moved to a new server/database or renamed.

For example, I could write a query like this:

insert into MyTable
(...)
select ... 
from remoteServer.remoteDatabase.dbo.Employee

but then if the server, or database, schema, or table changes it would impact my code. Instead I can create a synonym for the remote server and use the synonym instead:

insert into MyTable
(...)
select ... 
from EmployeeSynonym

If the underlying object changes location or name, I only need to update my synonym to point to the new object.

http://www.mssqltips.com/sqlservertip/1820/use-synonyms-to-abstract-the-location-of-sql-server-database-objects/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文