What is the difference between a schema and a table and a database?

后端 未结 14 957
一整个雨季
一整个雨季 2020-12-07 07:18

This is probably a n00blike (or worse) question. But I\'ve always viewed a schema as a table definition in a database. This is wrong or not entirely correct. I don\'t rememb

相关标签:
14条回答
  • 2020-12-07 07:44

    More on schemas:

    In SQL 2005 a schema is a way to group objects. It is a container you can put objects into. People can own this object. You can grant rights on the schema.

    In 2000 a schema was equivalent to a user. Now it has broken free and is quite useful. You could throw all your user procs in a certain schema and your admin procs in another. Grant EXECUTE to the appropriate user/role and you're through with granting EXECUTE on specific procedures. Nice.

    The dot notation would go like this:

    Server.Database.Schema.Object

    or

    myserver01.Adventureworks.Accounting.Beans

    0 讨论(0)
  • 2020-12-07 07:45

    A schema is not a plan for the entire database. It is a plan/container for a subset of objects (ex.tables) inside a a database.

    This goes to say that you can have multiple objects(ex. tables) inside one database which don't neccessarily fall under the same functional category. So you can group them under various schemas and give them different user access permissions.

    That said, I am unsure whether you can have one table under multiple schemas. The Management Studio UI gives a dropdown to assign a schema to a table, and hence making it possible to choose only one schema. I guess if you do it with TSQL, it might create 2 (or multiple) different objects with different object Ids.

    0 讨论(0)
提交回复
热议问题