H2 Database - Grant

H2 Database - Grant

Grant is a SQL grammar command used to grant rights to a table, user, or role. Administrator rights are required to run this command. This command commits an open transaction on this connection.

In this chapter, we will discuss different grant team scenarios.

Grant Right

Grant Right is a command to grant administrative rights to a table, user, or role.

Syntax

Following is the general syntax of the Grant command.

GRANT { SELECT | INSERT | UPDATE | DELETE | ALL } [,...] ON
{ { SCHEMA schemaName } | { tablename [,...] } }
TO { PUBLIC | username | roleName }

example

In this example, we will provide a read-only test table using the following command.

GRANT SELECT ON TEST TO READONLY

The above command produces the following output.

Grant successfully

Grant change to any schema

Grant Any Schema Change is a command to grant schema change rights to the appropriate user.

Syntax

The following is the general syntax for the "Give ability to change any schema" command.

GRANT ALTER ANY SCHEMA TO userName 

example

In this example, we will grant schema modification rights to a user named test_user . Make sure test_user exists. The following is a request to grant changing privileges.

GRANT ALTER ANY SCHEMA TO test_user;
The above query results in the following output.