BIT352 ยท 0 ยท 5 marks
What is privilege? Write commands to create user, grant privilege, revoke privilege and drop user in oracle database.
What is privilege? Write commands to create user, grant privilege, revoke privilege and drop user in oracle database. [5]
Quick answer
A privilege is a right or permission granted to a database user to perform a specific action on the database or on a specific database object. Privileges control what a user can do within the Oracle database system.
Privilege in Oracle Database
What is Privilege?
There are two types of privileges in Oracle:
- System Privileges - Allow users to perform specific actions on the database (e.g., CREATE TABLE, CREATE SESSION).
- Object Privileges - Allow users to perform specific actions on specific database objects like tables, views, sequences (e.g., SELECT, INSERT, UPDATE, DELETE on a table).
Oracle Database Commands
1. Create User
CREATE USER username IDENTIFIED BY password;
Example:
CREATE USER john IDENTIFIED BY john123;
2. Grant Privilege
GRANT privilege_name TO username;
Example (System Privilege):
GRANT CREATE SESSION TO john;
GRANT CREATE TABLE TO john;
Example (Object Privilege):
GRANT SELECT, INSERT ON employees TO john;
The
WITH GRANT OPTIONallows the user to further grant the privilege to others:
GRANT SELECT ON employees TO john WITH GRANT OPTION;
3. Revoke Privilege
REVOKE privilege_name FROM username;
Example (System Privilege):
REVOKE CREATE TABLE FROM john;
Example (Object Privilege):
REVOKE SELECT, INSERT ON employees FROM john;
4. Drop User
DROP USER username;
Example:
DROP USER john;
If the user owns database objects (tables, views, etc.), use
CASCADEto drop the user along with all their objects:
DROP USER john CASCADE;
Summary Table
| Operation | Command Syntax |
|---|---|
| Create User | CREATE USER name IDENTIFIED BY password; |
| Grant Privilege | GRANT privilege TO user; |
| Revoke Privilege | REVOKE privilege FROM user; |
| Drop User | DROP USER name [CASCADE]; |
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.