What is the proper syntax in SQL Server for addressing tables?

前端 未结 7 453
-上瘾入骨i
-上瘾入骨i 2021-01-18 10:05

This seems like a fairly obvious question, but I haven\'t been able to think of the proper term for what I am trying to ask, so coming up with reference material for this ha

7条回答
  •  爱一瞬间的悲伤
    2021-01-18 10:18

    In most cases i would always advise to use the full address just to be safe

        [databasename].[dbo].[some_table].[sometimesacolumngoeshere]
    

    However, this is only really needed when you have multiple databases. I only ever encountered one or two issues selecting databases and this is usually fixed by selecting the correct one in sql server.

    Once you are actually inside a query and you have given the table a shortened alias then there really is no need to include the full address because this is already referenced.

    E.G

       FROM [databasename].[dbo].[some_table].[sometimesacolumngoeshere] SOME
    
       SELECT SOME.Name
    

提交回复
热议问题