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

前端 未结 7 446
-上瘾入骨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:20

    Objects can be referred through a single or several identifiers.

    You can use a single identifier to refer to a object, but if the identifier is ambiguous, you must use more identifiers to uniquely identify the object.

    For example, two tables named TableA existing in different schemas must be referenced in the a query using at least a two identifiers, schema_one.TableA and schema_two.TableA.

    There's a MDSN page where you can find out more about object names and identifiers.

    Regarding the use of several identifiers for object names, if you are more specific, you reduce ambiguity in queries and speed up the parsing of the query, as the database engine doesn't have to resolve ambiguity problems, at the cost of readability of the queries.

    My personal preference (for the most commonly used objects) is using schema.Table when referencing tables and column, if a single table is referenced in the query, and table.column if multiple tables are referenced in the query.

提交回复
热议问题