Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use Roles or Schemas to give users access based on their department? [closed]

I want to give different level of access on tables to different users based on their department. Should I use Schema or Roles for this purpose?

like image 842
Vaibhav Jain Avatar asked Nov 11 '09 12:11

Vaibhav Jain


People also ask

Which of the following roles is recommended to be used to create and manage users and roles?

The user administrator (USERADMIN) role includes the privileges to create and manage users and roles (assuming ownership of those roles or users has not been transferred to another role).

Why are roles preferred in SQL?

A role is created to ease setup and maintenance of the security model. It is a named group of related privileges that can be granted to the user. When there are many users in a database it becomes difficult to grant or revoke privileges to users.

What is the difference between role and user in SQL?

A role is a privelege group, whereas a User is a person or Active Directory group. For example, an AD group "IT_Developers" may have Writer access to a database, but the AD group "Domain Administrators" aren't neccessarily admins on the database.

What database role is automatically granted to all users?

What role is automatically granted to all users? Public - all users are automatically a member of the public standard database role.


1 Answers

Roles would be the way to go here. Roles should be used anytime you have groups (i.e. depts. in your case) that need specific user rights to tables regardless of what schema they are in. This prevents errors, and makes the job of the DB administrator much easier.

Think of roles as groupings for users and the associated rights for that group of users, while schemas are for the logical grouping of sets of data.

Edit based on user comment:

You can, but to limit access to a particular table using schema is maybe not the best way to think about it. Schemas are used for grouping of data. So you may have a "sales" schema that has tables, procedures, etc. that are needed by the sales team. You can then say GRANT SELECT ON SCHEMA::sales TO salesRole; where you are using a schema as a shortcut to granting permissions to a group of users where each sales person granted the salesRole role. Any table that is later created in the sales schema will be selectable by the users with that role as well. If the sales team only uses this role and has no other permissions, then a table created in another schema will not be useable by those users. If that is what you mean by "restricting access using schema", then yes, but I prefer to look at it as the user not having rights granted either through a role or an explicit grant. Hope that this helps to clarify.

like image 62
RC. Avatar answered Oct 18 '22 05:10

RC.