How to use GRANT statement In SQL

The GRANT statement is an adaptable tool that can be used to allocate privileges granting fine-grained control over a user’s access to various database resources. The syntax for granting DBA role with admin option is:

GRANT DBA TO username WITH ADMIN OPTION;

This does not only give “anya” the DBA role but also allows her to pass it on to other users.

GRANT DBA TO anya WITH ADMIN OPTION;

Output:

GRANT DBA TO anya WITH ADMIN OPTION

On top of that, specific system privileges like creating tables and sessions may be granted one by one:

GRANT CREATE TABLE, CREATE SESSION TO username;

In this way, a more differentiated assignment of privileges can be made depending on individual requirements.

GRANT CREATE TABLE, CREATE SESSION TO anya;

Output:

Output

Explanation: In the above query we grants the user “anya” the permissions to create tables and to establish a session in the database. This allows “anya” to create new tables and to connect to the database for executing queries and accessing data.

How to Create a User With Full Privileges in PL/SQL?

In database administration, the ability to manage user privileges is very important. As a database administrator, we may find ourselves in the position of creating users with full privileges and granting them the authority to manage and manipulate the database.

In this article, we will learn about CREATE USERS and give them GRANT or Privileges to access information using various methods and examples too.

Similar Reads

How to Create a User with Full Privileges?

As a database administrator, one of our key responsibilities is to create users with full privileges often referred to as superusers or administrators. Below are three methods that can help us to CREATE USERS and give FULL Privileges to access information in PL/SQL are as follows:...

1. Using CREATE USER Statement

The CREATE USER statement is a fundamental command for database administrators allowing them to create new users and grant them specific privileges within the database. It requires specifying the username and password for the new user....

2. Using GRANT statement

The GRANT statement is an adaptable tool that can be used to allocate privileges granting fine-grained control over a user’s access to various database resources. The syntax for granting DBA role with admin option is:...

3. Using the DBMS_SQL Package

For a more programmatic approach to user privilege management in PL/SQL, the DBMS_SQL Package is used. This package allows for creating and running SQL statements within PL/SQL that are dynamic....

Conclusion

Overall, themanaging user privileges in database administration is important. In this article we have explored three methods in PL/SQL for creating users with full privileges. The CREATE USER statement allows for user creation, while the GRANT statement offers to get control over privileges. Additionally, the DBMS_SQL package provides a programmatic approach for dynamic SQL execution. Mastering these methods is essential for ensuring users have the necessary access to manage and manipulate the database effectively....