Saturday 14 March 2015

Oracle Database User Management

CREATING THE USER:
create user <USERNAME> identified by <PASSWORD> 
default tablespace <TABLESPACE NAME> 
temporary tablespace <TABLESPAC NAME> 
quota 30m on <TABLESPACE NAME>; 
Eg:
create user <John> identified by <John> 
default tablespace <users> 
temporary tablespace <temp> 
quota 30m on <users>; 
Above command creates a user chandra with password chandra. Consider the tablespace you have in which chandra will store his data is "USERS". The tablespace used for storing temporary segments will be "TEMP" and the amount of space which the user chandra can use on "USERS" tablespace is 30M.
DROPING THE USER:

            SQL> DROP USER John CASCADE;
 
ALTERING/UNLOCKING ACCOUNT: 
SQL> alter user john identified by john account unlock;

The above command alters or unlocks the "john" user with password "john".
SQL> select username, account_status, default_tablespace, 
temporary_tablespace, profile from dba_users 
where username = 'john';
SQL> select * from dba_ts_quotas where username = 'john'; 
GRANTING AND REVOKING PRIVILEGES:
Syntax:
SQL>GRANT <PRIVILAGE> TO <USERNAME>
SQL>REVOKE <PRIVILAGE> FROM <USERNAME>
Eg:
SQL> GRANT create table to john;‎ 
SQL> GRANT create session to john;
SQL> GRANT create any table, create tablespace to john;
SQL> REVOKE create any table from john;
SQL> REVOKE create tablespace from john;
SQL> GRANT select, insert, update, delete on <TABLENAME> to john;
SQL> REVOKE update,delete on USERS.PAY_PAYMENT_MASTER from john;
 
ROLES:
Creating Roles
Create Role
CREATE ROLE <role_name>;
CREATE ROLE read_only;
Create Password Protected Role
CREATE ROLE <role_name> IDENTIFIED BY <password>;
CREATE ROLE dba IDENTIFIED BY "johnny";

Assigning Privileges And Roles To Roles
Assign Privilege To A Role
GRANT <privilege_name> TO <role_name>;
GRANT create session TO read_only
Create A Role Heirarchy
GRANT <role_name> TO <role_name>;
CREATE ROLE ap_clerk;

GRANT read_only TO ap_clerk;
GRANT select ON general_ledger TO ap_clerk;
GRANT insert ON ap_master TO ap_clerk;
GRANT update ON ap_master TO ap_clerk;
GRANT insert ON ap_detail TO ap_clerk;
GRANT update ON ap_detail TO ap_clerk;
Add Another Layer To The Heirarchy
GRANT <roles and privileges> TO <role_name>;
CREATE ROLE ap_manager IDENTIFIED BY appwd;

GRANT ap_clerk TO ap_manager;
GRANT delete ON ap_master TO ap_manager;
GRANT delete ON ap_detail TO ap_manager;
GRANT select any table TO ap_manager;

Assigning Roles
Assigning Roles To Users
GRANT <roles_name> TO <user_name>;
GRANT read_only TO jbiden;

GRANT ap_clerk TO jstough;
GRANT ap_clerk TO ckeizer;
GRANT ap_clerk TO rallen;

GRANT ap_manager TO escott;

Revoking Privileges From Roles
Revoke Privilege
REVOKE <privilege_name> FROM <role_name>;
REVOKE select any table FROM ap_manager;

Revoking Roles
Revoke a role from a user
REVOKE <role_name> FROM <user_name>;
REVOKE ap_manager FROM escott;
Revoke A Role And Drop Any Invalidated Constraints
REVOKE ALL ON <table_name>
FROM <schema_name> 
CASCADE CONSTRAINTS;
REVOKE ALL ON invoices
FROM abc 
CASCADE CONSTRAINTS;

Activating & Decactivating Roles
Activating A Role
SET ROLE <role_name>;
SET ROLE ap_clerk;
Activating A Password Protected Role
SET ROLE <role_name> IDENTIFIED BY <role_password>;
SET ROLE ap_manager IDENTIFIED BY appwd;
Activating All Roles
SET ROLE all;
Activating All Roles Except One
SET ROLE all EXCEPT <role_name>;
SET ROLE all EXCEPT ap_manager;
Deactivating A Role
Can not be done on an indiviDUAL basis
Deactivating All Roles
SET ROLE none;

Drop Role
Dropping A Role 
DROP ROLE <role_name>;
DROP ROLE manager_role; 

No comments:

Post a Comment