开发者

Why does SQL Server Create Schemas for the initial DB Roles?

Why does SQL Server create schemas for the initial DB roles, such as db_accessadmin, db_datareader, etc.? I understand the roles and why they exist, but I don't understand why they are given schemas when the database is created. Does anybody use them? I can't imagine that Microsoft recommends add开发者_开发知识库ing tables to them. I can't see adding an employee or product table to db_datawriter. Are there some kind of hidden system objects owned by them?


Others have said legacy/backwards compatibility without really explaining it.

When SQL Server 2005 was introduced, they introduced user/schema separation. Before that time, each user and role implicitly had a schema of the same name associated with it (and there was no way to create schemas, other than by creating users or roles).

So, for those built in roles that existed in the 2000 (or earlier) versions of SQL Server, there was always a schema "available" in the database with the same name as that role. So some code may have been written assuming that such schemas existed; later versions of SQL Server ensure this is still true, to avoid breaking such code.


Legacy.

You should use explicit GRANT (say GRANT ALTER USER TO ...) rather then using the legacy fixed database roles.

If you use sp_grantdbaccess you also get a schema created: you should be using CREATE USER

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜