Monday, 9 January 2017

Creating Roles


A role is a group of privileges. The privileges can be assigned to a role, and then the role can be granted to multiple users and roles. When adding or deleting a privilege from a role, all users and roles assigned that role automatically receive or lose that privilege. A user or role can have multiple roles. A role can have a password. The roles can help you manage multiple privileges assigned to multiple users.

Creating Roles

To create a role, you must have the CREATE ROLE system privilege.

GRANT CREATE ROLE TO store;
GRANT CREATE USER TO store WITH ADMIN OPTION;
You create a role using the CREATE ROLE statement. The default is to do both.

CREATE ROLE firstRole;
CREATE ROLE secondRole IDENTIFIED by password;

GRANT SELECT, INSERT, UPDATE, DELETE ON employee TO firstRole;
GRANT SELECT, INSERT, UPDATE, DELETE ON products TO firstRole;
GRANT firstRole TO secondRole;