liveBook · Manning

Grant statement

As explained in Grokking Relational Database Design

A GRANT statement assigns specified database privileges to a role or user.

A GRANT statement assigns database privileges to a role or user. Use it to control who can view, add, change, or delete data. In a role-based access control design, create a role, grant privileges to it, then assign the role to users. section 7.4

Match each privilege to the job a role must perform:

  • GRANT SELECT lets a role view table records. section 7.4
  • GRANT INSERT lets a role add records, such as purchases or reviews. section 7.4
  • GRANT SELECT, INSERT, UPDATE, DELETE gives an administrator broad control over selected tables. section 7.4

Assign a purchasing role

Create standard_user, grant it SELECT on product and INSERT on purchase, purchase_product, and review, then assign it to a user: GRANT SELECT ON database_name.product TO standard_user; GRANT INSERT ON database_name.purchase TO standard_user; GRANT standard_user TO 'morpheus'@'%';

How Grokking Relational Database Design covers it

How deep it goes
Explains privilege meanings and demonstrates role creation, grants, user assignment, and default-role activation.
Examples
Uses standard_user, analyst, and admin roles across product, purchase, purchase_product, and review tables.
What it assumes
Assumes identified user roles and database tables, while explaining privilege meanings and role assignment.
What you can do after
Apply it via SQL to create roles, grant table privileges, assign roles, and enable default roles.
How it connects
Connects database privileges with roles, users, RBAC, and table operations such as SELECT, INSERT, UPDATE, and DELETE.

Also explained in

Compare how 3 books explain grant statement →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Relational Database Design. The section links point to the parts of the book it draws on.