SQL Server 架构和默认架构
我的数据库中有一个模式定义。除了现在每次执行 sql 语句时我都必须提供模式...... SELECT * FROM [myschema].table
我使用 Management Studio 为我的用户设置了默认架构,并运行了 使用 DEFAULT_SCHEMA [myschema] 更改用户 myUser
并且在编写没有架构的查询时(SELECT * FROM table)我仍然得到无效的对象“table”
有没有一种方法可以编写 SELECT * FROM table
而不必一直指定架构名称?
它在 SQL 2005 上使用 SQL Management Studio。
I have a schema define in my database. Except now everytime I do a sql statement I have to provide the schema ...SELECT * FROM [myschema].table
I set the default schema for my user using management studio and also ran theALTER USER myUser WITH DEFAULT_SCHEMA [myschema]
and I still get the invalid object 'table' when writing a query without the schema (SELECT * FROM table)
Is there a way to write SELECT * FROM table
without having to specify the schema name all the time?
It's on SQL 2005 using SQL Management Studio.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
用户是否是
SA
,如果是,则根据 文档SA
用户始终默认使用dbo
架构。Is the user an
SA
, if so it will not work, according to the documentationSA
users are always defaulted to thedbo
schema.有几个选项:
为要引用的表创建同义词:< /p>
...这将影响在该数据库上下文中不使用至少两个名称表示法的每个人。 在此处了解更多信息。但它最终与架构相关联。
检查在“可用数据库”下拉列表(左上角,执行按钮左侧)中选择的数据库是否正确。
指定表(和视图)引用时使用三个名称表示法:
<前><代码>选择*
FROM [your_db].[your_schema].table_name
Couple of options:
Create a synonym for the table you want to reference:
...which will affect everyone who doesn't use at least two name notation, in the context of that database. Read more about it here. But it is associated ultimately to a schema.
Check that the database selected in the "Available Databases" drop down (upper left, to the left of the Execute button) is correct.
Use three name notation when specifying table (and view) references:
如果您不想使用“完全限定”SQl 名称,则需要避免使用未使用分配的“dbo”默认架构的任何帐户或角色创建表。如果您不打算使用用户的默认架构,为什么需要更改它?
If you do not want to use "full qualified" SQl names, then you need to avoid creating your tables using any account or role that's not using the "dbo" default schema assigned. Why do you need to change the default schema on the user if you don't plan on using it?