SQL 中同义词的优点?
为什么使用同义词? SQL 中 syNONYMS 的优点?
why synonyms are used?,advantages of syNONYMS IN SQL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
为什么使用同义词? SQL 中 syNONYMS 的优点?
why synonyms are used?,advantages of syNONYMS IN SQL?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
它们只是数据库内对象的简写名称。例如,如果数据库中有名为
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 calledProductionControl.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.来自 MSDN 了解同义词
From MSDN Understanding Synonyms
在某些企业系统中,您可能必须处理您无法控制的远程对象。例如,由其他部门或团队维护的数据库。
同义词可以帮助您将基础对象的名称和位置与 SQL 代码解耦。这样,即使您想要的表被移动到新的服务器/数据库或重命名,您也可以针对同义词表进行编码。
例如,我可以编写这样的查询:
但是如果服务器、数据库、模式或表发生更改,则会影响我的代码。相反,我可以为远程服务器创建一个同义词并使用该同义词:
如果底层对象更改位置或名称,我只需更新同义词以指向新对象。
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:
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:
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/