Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
539 views
in Technique[技术] by (71.8m points)

sql - Double Dot table qualifier

I am looking at a new database schema developed by an external vendor. There are two databases:

Database1
Database2

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

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.

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:

  1. The schema is empty in the sql statement i.e. there is no text in between the two dots.
  2. The Person table is part of the dbo schema in database2.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Thanks to this dot, the default schema (dbo) is choosen for your query.

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

if we create select statement like:

select * from Database2..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

EDIT: As colleagues pointed out, the default schema can be changed in database, however in this particular example it seems to be dbo :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...