SQL Server 2014 - 使用没有架构限定的名称
SQLServer 2014 - using name without schema qualification
我有 table 和同名视图:"dbo.Users" (table) 和 "www.Users" (table)。整个代码中有 select
个语句,如下所示:
SELECT u_id, u_name from Users WHERE ...
我检查了两个不同的用户,似乎在这两种情况下都使用了视图。管理这种情况的具体规则是什么?我尝试寻找 name binding
、name search order
和类似的东西,但无法在文档中找到任何结论。
所使用的默认架构由数据库用户的 "default schema" 属性 管理。
您可以从 CREATE USER
文档中阅读:
The default schema will be the first schema that will be searched by the server when it resolves the names of objects for this database user.[...]
当没有为用户指定默认架构时,还有更多内容:
If the user has a default schema, that default schema will used. If the user does not have a default schema, but the user is a member of a group that has a default schema, the default schema of the group will be used. If the user does not have a default schema, and is a member of more than one group, the default schema for the user will be that of the Windows group with the lowest principal_id and an explicitly set default schema. (It is not possible to explicitly select one of the available default schemas as the preferred schema.) If no default schema can be determined for a user, the dbo schema will be used.
为避免发生类似情况,请始终通过为查询中引用的数据库对象指定架构来明确说明。
我有 table 和同名视图:"dbo.Users" (table) 和 "www.Users" (table)。整个代码中有 select
个语句,如下所示:
SELECT u_id, u_name from Users WHERE ...
我检查了两个不同的用户,似乎在这两种情况下都使用了视图。管理这种情况的具体规则是什么?我尝试寻找 name binding
、name search order
和类似的东西,但无法在文档中找到任何结论。
所使用的默认架构由数据库用户的 "default schema" 属性 管理。
您可以从 CREATE USER
文档中阅读:
The default schema will be the first schema that will be searched by the server when it resolves the names of objects for this database user.[...]
当没有为用户指定默认架构时,还有更多内容:
If the user has a default schema, that default schema will used. If the user does not have a default schema, but the user is a member of a group that has a default schema, the default schema of the group will be used. If the user does not have a default schema, and is a member of more than one group, the default schema for the user will be that of the Windows group with the lowest principal_id and an explicitly set default schema. (It is not possible to explicitly select one of the available default schemas as the preferred schema.) If no default schema can be determined for a user, the dbo schema will be used.
为避免发生类似情况,请始终通过为查询中引用的数据库对象指定架构来明确说明。