In SQL Server 2005 is there a way to set the default schema to anything other than dbo when the user has admin rights? [duplicate]

旧时模样 提交于 2019-12-12 18:34:51

问题


I am using SQL Server 2005 with Windows authentication. My login has administrator rights. For my login I have a user mapped to a database with the default schema set to "my_schema". My login is not the owner of the database. When I log on though, and try to execute a simple select statement on a table in "my_schema" without specifying the schema name, I get an invalid object error. This does not happen when I log on as a user with no admin privileges. What I think is happening is that SQL Server is changing the default schema to "dbo" because I have admin rights. Is there a way to work around this?


回答1:


Sysadmin role members always get defaulted to dbo. It is a designed behaviour and cannot be overruled.

You are best off moving the user out of the Sysadmin role and back into the "normal" userspace




回答2:


You can set the default schema with the "DEFAULT_SCHEMA" option using either the CREATE USER or ALTER USER commands

CREATE USER exampleUser WITH DEFAULT_SCHEMA = exampleDB;
ALTER USER exampleUser WITH DEFAULT_SCHEMA = exampleDB;


来源:https://stackoverflow.com/questions/3292633/in-sql-server-2005-is-there-a-way-to-set-the-default-schema-to-anything-other-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!