Database Management: Creating and Granting User Access in Oracle

Written by luca1iu | Published 2024/03/13
Tech Story Tags: database | sql | oracle | data-security | data-engineering | database-management | oracle-database | sql-commands

TLDROftentimes, colleagues from different departments need quick access to specific datasets. The traditional method of exporting Excel files from databases is inefficient and time-consuming. A more effective approach involves creating new user accounts in the database. This allows colleagues to seamlessly connect to the database using tools like Power BI or Power Query.via the TL;DR App

Introduction

Proficiency in database management is an essential skill for data analysts. Oftentimes, colleagues from different departments need quick access to specific datasets, making the traditional method of exporting Excel files from databases inefficient and time-consuming. A more effective approach involves creating new user accounts in the database and granting them appropriate viewing rights. This allows colleagues to seamlessly connect to the database using tools like Power BI or Power Query, enabling them to access necessary data tables promptly and efficiently. This streamlined process fosters collaboration and supports data-driven decision-making across organizational departments.

Creating a new user

To create a new user in the Oracle database, you can execute the following SQL command:

CREATE USER 'USERNAME' IDENTIFIED BY 'PASSWORD';

For example:

CREATE USER TEST_USER IDENTIFIED BY TEST123;

Granting the Connect Role

After creating a new user, attempting to connect may result in an error message:

[72000][1045] ORA-01045: user TEST_USER lacks CREATE SESSION privilege; logon denied

To enable the user to connect to the database, you must grant the CONNECT role:

GRANT CONNECT TO TEST_USER;

Merely connecting is not enough - make sure to grant the RESOURCE privilege to allow access to the tables.

GRANT CONNECT, RESOURCE TO TEST_USER;

Table privilege

To grant specific privileges on tables to a user, you can utilize the GRANT command on specific table TO user. For example:

GRANT SELECT ON schema.table_name TO TEST_USER;

If you wish to provide the user with options beyond selection, such as insertion, updating, and deletion, you may proceed with the execution of the following command.

GRANT SELECT, INSERT, UPDATE, DELETE ON schema.table_name TO TEST_USER;

Delete a user

To remove a user from the database, you can execute the following SQL command:

DROP USER TEST_USER;

Thank you for taking the time to explore data-related insights with me. I appreciate your engagement. If you find this information helpful, I invite you to follow me or connect with me onΒ LinkedIn or X(@Luca_DataTeam). You can also catch glimpses of my personal life on Instagram, Happy exploring!πŸ‘‹


Also published here.


Written by luca1iu | Hello there! πŸ‘‹ I'm Luca, a BI Developer with a passion for all things data, Proficient in Python, SQL and Power BI
Published by HackerNoon on 2024/03/13