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:
Double-dot notation follows this format: <NPS_DatabaseName>..<NPS_ObjectName> The two dots indicate that the schema name is not specified.
The dbo schema is the default schema of every database. By default, users created with the CREATE USER Transact-SQL command have dbo as their default schema. The dbo schema is owned by the dbo user account. Users who are assigned the dbo as default schema don't inherit the permissions of the dbo user account.
The colon (:) is used to select "slices" from arrays. (See Section 5.12.) In certain SQL dialects (such as Embedded SQL), the colon is used to prefix variable names. The asterisk (*) has a special meaning when used in the SELECT command or with the COUNT aggregate function.
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 :)
This is a database schema. Full three-part name of a table is:
databasename.schemaname.tablename
For a default schema of the user, you can also omit the schema name:
databasename..tablename
You can also specify a linked server name:
servername.databasename.schemaname.tablename
You can read more about using identifiers as table names on MSDN
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With