{"id":3999,"date":"2025-06-07T09:28:13","date_gmt":"2025-06-07T09:28:13","guid":{"rendered":"https:\/\/w3buddy.com\/?post_type=cposts&#038;p=3999"},"modified":"2026-09-26T13:15:25","modified_gmt":"2026-09-26T07:45:25","slug":"sql-grant-revoke-permissions","status":"publish","type":"post","link":"https:\/\/w3buddy.com\/blog\/sql-grant-revoke-permissions\/","title":{"rendered":"SQL GRANT \/ REVOKE (Permissions)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>GRANT<\/code> and <code>REVOKE<\/code> statements are used to manage <strong>user access and privileges<\/strong> in SQL. These ensure users have only the permissions they need \u2014 nothing more.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udd10 <strong>Why Use GRANT \/ REVOKE?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To <strong>control who can do what<\/strong> in the database:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Read data (<code>SELECT<\/code>)<\/li>\n\n\n\n<li>Modify data (<code>INSERT<\/code>, <code>UPDATE<\/code>, <code>DELETE<\/code>)<\/li>\n\n\n\n<li>Execute procedures<\/li>\n\n\n\n<li>Manage tables or users<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udd39 <strong>GRANT \u2013 Give Permissions<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Syntax\nGRANT privilege &#91;, ...] ON object TO user;\n\n-- Example: Allow user to select and insert on employees table\nGRANT SELECT, INSERT ON employees TO john;<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can also grant privileges with <code>WITH GRANT OPTION<\/code> to allow users to grant to others:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udd39 <strong>REVOKE \u2013 Remove Permissions<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>GRANT SELECT ON employees TO john WITH GRANT OPTION;<\/code><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Syntax\nREVOKE privilege &#91;, ...] ON object FROM user;\n\n-- Example: Remove insert permission\nREVOKE INSERT ON employees FROM john;<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This ensures the user can no longer perform those operations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udd39 <strong>Common Privileges<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Privilege<\/th><th>Action Allowed<\/th><\/tr><\/thead><tbody><tr><td>SELECT<\/td><td>Read rows<\/td><\/tr><tr><td>INSERT<\/td><td>Add new rows<\/td><\/tr><tr><td>UPDATE<\/td><td>Modify existing rows<\/td><\/tr><tr><td>DELETE<\/td><td>Remove rows<\/td><\/tr><tr><td>EXECUTE<\/td><td>Run stored procedures\/functions<\/td><\/tr><tr><td>ALL<\/td><td>Grants all applicable rights<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83e\udde0 <strong>Quick Recap<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Key Point<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>GRANT<\/code><\/td><td>Assigns privileges to a user<\/td><\/tr><tr><td><code>REVOKE<\/code><\/td><td>Removes previously granted privileges<\/td><\/tr><tr><td>Objects<\/td><td>Tables, views, procedures, etc.<\/td><\/tr><tr><td>Best Practice<\/td><td>Grant minimum permissions needed<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Always apply the <strong>principle of least privilege<\/strong> for better database security.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The GRANT and REVOKE statements are used to manage user access and privileges in SQL. These ensure users have only the permissions they need \u2014 nothing more. \ud83d\udd10 Why Use GRANT \/ REVOKE? To control who can do what in the database: \ud83d\udd39 GRANT \u2013 Give Permissions You can also grant privileges with WITH GRANT [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"googlesitekit_rrm_CAowu461DA:productID":"","footnotes":""},"categories":[1225,979],"tags":[],"class_list":["post-3999","post","type-post","status-publish","format-standard","hentry","category-database","category-sql"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/3999","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/comments?post=3999"}],"version-history":[{"count":1,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/3999\/revisions"}],"predecessor-version":[{"id":4000,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/3999\/revisions\/4000"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=3999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=3999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/tags?post=3999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}