SQL Server 创建错误的表名,为什么?
问题:当我使用 SQL Server Management-Studio 创建表 (T_TableName
) 时,它总是创建表 as
Domain\UserName.T_TableName
而不是 出了
dbo.T_TableName
什么问题?
Question: when I create a table (T_TableName
) using SQL Server Management-Studio, it always creates the table as
Domain\UserName.T_TableName
instead of
dbo.T_TableName
What's wrong ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您没有在要创建的表名上显式指定架构,它将在用户当前的默认架构中创建。
我敢打赌,您使用的用户将自己的个人架构设置为默认架构 - 这就是为什么您的表是在他自己的个人架构中创建的。
您可以通过检查 sys.database_principals 来检查您拥有哪些数据库用户以及他们的默认架构(SQL Server 2005 及更高版本):
要解决此问题:
指定您要显式使用的架构 (无论如何,最好的做法!)
将用户的默认架构更改为
dbo
但作为一般经验法则,我建议始终使用“dbo”。如果您希望将所有数据库对象都包含在 dbo 架构中,请显式添加前缀。也有助于提高性能(非常轻微),因为如果您明确告诉 SQL Server 您的数据库对象所在的位置,它就不必在不同的模式中寻找。
If you don't specify a schema explicitly on your table name to be created, it will be created in the user's current default schema.
I bet the user you're using has its own personal schema set as its default schema - that's why your tables get created in his own personal schema.
You can check what database users you have and what their default schema is by inspecting
sys.database_principals
(SQL Server 2005 and up):To solve this:
specify the schema you want to use explicitly (best practice anyway!)
change the user's default schema to
dbo
But as a general rule of thumb, I recommend always using the "dbo." prefix explicitly, if you want to have all your database objects in the dbo schema. Helps with performance, too (ever so slightly) since SQL Server won't have to go hunting in different schemas, if you explicitly tell it where your db objects live.
您需要将表创建为“dbo.Whatever”,或者需要通过发出如下命令来更改默认架构(或让您的 SA 为您执行此操作):
You need to either create your table as "dbo.Whatever", OR you need to change your default schema (or have your SA do it for you) by issuing a command like:
在 SSMS 中将其称为 dbo.T_TableName。如果您拥有正确的权限,它将起作用。
Call it dbo.T_TableName in SSMS. If you have the correct permissions, it will work.
您是否被指定为创建表的数据库的
db_owner
?如果不是,这可能就是问题所在。尝试将用户映射权限添加到数据库中。Are you assigned as
db_owner
for the database you created the table in? If not, this could be the issue. Try adding your user mapping permissions to the database as such.