双点表限定符 [英] Double Dot table qualifier
问题描述
我正在查看由外部供应商开发的新数据库架构.有两个数据库:
I am looking at a new database schema developed by an external vendor. There are two databases:
Database1
Database2
他们给我发送了一条 SQL 语句,用于连接两个数据库之间的表.有些地方他们使用了双点符号.我以前从未见过这个.请看下面的SQL语句(这不是他们发给我的语句):
They have sent me an SQL statement that joins tables between the two databases. There are places where they have used a double dot notation. I have never seen this before. Please see the SQL statement below (this is not the statement they sent me):
select * from database2..Person
上面的语句是从 database1 运行的.为什么有两个点?如果我删除其中一个点,则查询不会运行.
The statement above is run from database1. Why does it have two dots? If I remove one of the dots then the query does not run.
我做了一些谷歌搜索,发现了这个:http://www.sqlservercentral.com/Forums/Topic585446-338-1.aspx.这表明它指的是模式.但是:
I have done some Googling and came across this: http://www.sqlservercentral.com/Forums/Topic585446-338-1.aspx. This suggests it is referring to the schema. However:
- sql 语句中的架构为空,即两点之间没有文本.
- Person 表是 database2 中 dbo 架构的一部分.
推荐答案
多亏了这个点,为您的查询选择了默认架构 (dbo).
Thanks to this dot, the default schema (dbo) is choosen for your query.
当您有两个数据库时,需要提供表的完整路径.如果我们有:数据库 1 架构:dbo,来宾表 dbo.A,来宾:ADatabase2 架构:dbo,来宾表 dbo.B,来宾:B
When you have two databases it is required to give the full path to the table. If we have: Database1 schema: dbo, guest table dbo.A, guest: A Database2 schema: dbo, guest table dbo.B, guest: B
如果我们创建如下的 select 语句:
if we create select statement like:
select * from Database2..B
select * from Database2..B
我们正在从 dbo.B 表中选择数据如果我们想指定我们需要引用的架构
We are selecting data from dbo.B table IF we would like to specify schema we need to refer as
select * from Database2.schemaname.tablename
正如同事所指出的,可以在数据库中更改默认架构,但是在这个特定示例中,它似乎是 dbo :)
As colleagues pointed out, the default schema can be changed in database, however in this particular example it seems to be dbo :)
这篇关于双点表限定符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!