Monday, January 13, 2014

How to create a user with read only priviliges for the schema

This ain´t an easy task as I thought you will need to run some commands before you have it going.

In this case let's assume that you already have the database created and the required accounts and that you are familiar with sqlplus

1) Login as system
sqlplus system/pwd@SID




2) You will need to create the user

CREATE USER your_user IDENTIFIED BY yourPassword;


This user will be created on the default tablespace




3)  Allow the user to create a session and view the table names

GRANT CREATE SESSION TO your_user;
GRANT SELECT ON SYS.EXTERNAL_TAB$ to your_user;



4) Create the queries to grant permissions on every table:
SELECT 'GRANT SELECT ON your_schema.' ||TABLE_NAME || ' TO your_user;' FROM DBA_TABLES WHERE OWNER='schema_owner';



5) Execute the result of the previous query
GRANT SELECT ON your_schema.Table1 TO DEVELS;
GRANT SELECT ON  your_schema.Table2 TO DEVELS;
...
GRANT SELECT ON  your_schema.TableN TO DEVELS;

Now your will have a user that can only see the data there

No comments:

Post a Comment