How to set the default schema of a database in SQL Server 2005?

前端 未结 3 830
挽巷
挽巷 2020-12-06 09:30

The following line works:

SELECT * FROM [myschema].users

But this does not:

SELECT * FROM users
3条回答
  •  难免孤独
    2020-12-06 10:04

    A default schema is user-specific:

    USE yourDatabase;
    ALTER USER [yourUser] WITH DEFAULT_SCHEMA = myschema;
    

    More information about the ALTER TABLE for SQL 2005 might help you as well.

    As this is user-specific, if you have multiple users, you will need to execute this query (on each database) for each user whose default schema you want to update.

    It is important to note:

    The value of DEFAULT_SCHEMA is ignored if the user is a member of the sysadmin
    fixed server role. All members of the sysadmin fixed server role have a default
    schema of dbo.
    

提交回复
热议问题