简体   繁体   中英

What does 'reference..' mean in SQL syntax?

from
[PMDB].[dbo].PROJECT P
inner join PROJWBS PW on P.proj_id = PW.proj_id
and PW.proj_node_flag = 'Y' and PW.wbs_short_name not like '%- B%'
and PW.status_code <> 'WS_Planned' and PW.status_code <> 'WS_Whatif'
inner join [PMDB].[dbo].TASKSUM TS on PW.proj_id = TS.proj_id and PW.wbs_id = TS.wbs_id
inner join reference..fiscal_year_qtr_month FYQM on isnull(TS.act_end_date,P.scd_end_date) > FYQM.fiscal_month_begin_datetime
and isnull(TS.act_end_date,P.scd_end_date) <= FYQM.fiscal_month_end_datetime
inner join reference..mfg_year_month_ww MYMW on isnull(TS.act_end_date,P.scd_end_date) > MYMW.mfg_ww_begin_datetime
a

I have tried the internet, but just don't understand what does the 'reference..' mean here. Am I missing something?

reference is a database name. In between the database name and the object name goes the schema.

So if you want to query from sys.database_files in master , you would say:

SELECT name FROM master.sys.database_files;
---- database ---^^^^^^
------------- schema ---^^^
----------------- object ---^^^^^^^^^^^^^^

You can leave out the schema if you know the entity name is unambiguous. For catalog views/DMVs, you can't leave it out, but if you're using your default schema (usually dbo), you can leave out the explicit reference. Not that that's a good idea .

reference..mfg_year_month_ww

is the short hand for

reference.dbo.mfg_year_month_ww

basically it means use default schema.

That's T-SQL (Microsoft-specific) syntax indicating the table's name and owner. The default owner is "dbo". The default database is whichever one you're currenting "using".

Here are more details:

http://examplesql.com/sqlserver-t-sql-tsql/dbo-dotdot-syntax/

SELECT * FROM AdventureWorks2008.dbo.AWBuildVersion;

Truth be told, it isn't rocket science. '..' can be used as a replacement for dbo when referring to the default schema in a tsql query. If you need to access the default database frequenty, the dbo .. syntax shortcut can greatly increase your efficiency.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM