Lecture Notes Unit4 Chapter13 users , roles and privileges

1,174 views 25 slides Jul 17, 2024
Slide 1
Slide 1 of 25
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25

About This Presentation

Description:
Welcome to the comprehensive guide on Relational Database Management System (RDBMS) concepts, tailored for final year B.Sc. Computer Science students affiliated with Alagappa University. This document covers fundamental principles and advanced topics in RDBMS, offering a structured appr...


Slide Content

RDBMS -Unit IV
Chapter 13
Users, Privileges and Roles
Prepared By
Dr. S.Murugan, Associate Professor
Department of Computer Science,
AlagappaGovernment Arts College, Karaikudi.
(Affiliated by AlagappaUniversity)
Mailid: [email protected]
Reference Book:
LEARN ORACLE 8i, JOSE A RAMALHO

USER
➢Theregisteredpersoninanoracleiscalleduser.
➢Each registered user has an access password.
➢individual privileges or roles assigned to every user.

The CREATE USER Command
➢The CREATE USER command is responsible for the creation of
new users.
➢SYNTAX
CREATE USER USERNAME IDENTIFIED BY PASSWORD
➢Arguments:
➢user
The name of the user to be created.
➢IDENTIFIED
Indicates how Oracle validates the user.
➢BY password
Requires the user to specify this password for the
connection.

Creating a New User
➢Tocreatenewuserorassignprivileges,youmust
connecttotheadministratorusingtheSystemname
andthemanagerkeyword.
Connectsystem/manager
➢First,let’screateausercalledcs8001,withthe
passwordComputer
➢SQL>CREATEUSERcs8001IDENTIFIEDBY
computer;
Usercreated.

The GRANT Command
➢Thegrantcommandisusedtoassignprivilegeorroles
totheuser.
➢Syntax
GRANTsystemprivileges/roleTOuser/role
Arguments:
privilege
The name of the privilege to be assigned.
user/role
The name of the user or role that is receiving the
privilege.

The GRANT Command Example
➢Let’sconnectasSystemandassigntheRESOURCEprivilege,
whichallowsaccesstothedatabaseandthecreationoftables,
sequences,procedures,triggers,indexes,andclusters.
➢SQL>connectsystem/manager;
Connected.
➢SQL>grantRESOURCEtocs8001;
Grantoperationsuccessful.
➢Nowtheusercs8001abletocreatetable,procedure,etc.
➢SQL>connectcs8001/computer;
Connected.
➢SQL>createtablex(anumber);
Tablecreated.

Deleting a User
➢YoucanremoveadatabaseuserwiththeDROPUSER
command.
➢Thiscommandremovesboththeuserandallthe
objectscontainedinthisuser’sschema.
Syntax:
DROP USER user_name
In the next example user cs8001 is removed:
SQL> connect system/manager
Connected.
SQL> drop user cs8001 cascade;
Users eliminated.
To display all users
SQL> select * from all_users;

Privileges
➢Aprivilegeisanauthorizationgiventotheuserto
accessandmanipulateadatabaseobjectinacertain
way.
➢Forexample,oneusercanbeassignedtheprivilegeto
selecttablesbutnotchangethem.
➢Therearetwotypesofprivileges:systemprivileges
andobjectprivileges.

System Privileges
➢Asystemprivilegeistherightorpermissiontoexecute
certaindatabaseactionsinaspecifictypeofdatabase
object.
➢Therearemorethan70typesofprivilegesassociated
totheactionsofadatabase.
➢Thenameoftheprivilegeissimilartothenameofthe
actionitexecutes.
➢Forexample,aprivilegecalledALTERTABLEgrants
ausertherighttomodifyatable.

Object Privileges
➢Anobjectprivilegeistherighttoperformcertain
actionsinaspecificobject,suchastherighttoinclude
arowinatable.

Object Privileges
➢AvariationoftheGRANTcommandallowsyouto
assignobjectprivilegestoauserorrole.
➢Theprivilegesassignedcanbe:SELECT,ALTER,
DELETE, EXECUTE, INSERT, INDEX,
REFERENCE,andUPDATE.
➢Thefollowingobjectscanbeassignedprivileges:
tables,views,sequences,snapshots,andsynonyms.
➢Anyuserwhohasauthoritycangrantprivilegeson
tables.

Object Privileges

Object Privileges
Options:
SELECT:Toselectdatainatableorview.
INSERT:Toinsertrowsinatableorview.
DELETE:Toeliminaterowsinatableorview.
UPDATE:Toupdateatableand,optionally,updateonly
thespecifiedcolumns.
INDEX:Tocreateoreliminatetheindexesofatable.
ALTER:Tomodifyatable.
ALL:Toperformalltheaboveprivileges.

Object Privileges
ALL:Toperformalltheaboveprivileges.
table_name:Namesofexistingtablesinthedatabase.
view_name:Namesofexistingviewsinthedatabase.
column_name:Thisisoptionalanddeterminesthe
columnsoftablesorviewsspecifiedintheONclause.
Thenamesofthecolumnsmustnotbequalified.
USER:Nameoftheusertowhomtheprivilegeis
assigned.

Object Privileges
PUBLIC:Meansthatallthecurrentandnewusershave
theprivilegesspecifiedforthetableorview.
WITHADMINOPTION:
Allowstheuserorrolethatreceivesthe
privilegetograntittootherusers,modifyit,oreven
deleteit.

Grant Object Privileges
System/manager Cs8001/computer
Connect system/manager
Connected.
Connect cs8001/computer
Connected.
grant select on empto cs8001
GRANT operation successful
SQL> select enamefrom
system.emp;
SQL> grant update (DNAME) on
deptto cs8001;
SQL> update system.dept
set dname=’SALES FORCE’
where deptno=30;
1 row updated.
SQL> update system.dept
set loc=’MIAMI’
where deptno=30;
update system.dept
*
ERROR on row 1:
ORA-01031: insufficient

Viewing Users
➢Youcanuseoneofthetablesofthedatadictionaryto
checkthedatabaseusers.Thedictionaryviewthat
maintainsthislistisALL_USERS.
➢SQL>select*fromall_users;

Revoke Object previleges
System/manager Cs8001/computer
Connect system/manager
Connected.
Connect cs8001/computer
Connected.
revoke select on empfrom
cs8001
Revoke successful
SQL> select enamefrom
system.emp;
It will displayserror
SQL> revoke update
(DNAME) on deptto
cs8001;
SQL> update system.dept
set dname=’SALES FORCE’
where deptno=30;
It will displayserror.

Viewing Users
➢Youcanuseoneofthetablesofthedatadictionaryto
checkthedatabaseusers.Thedictionaryviewthat
maintainsthislistisALL_USERS.
➢SQL>select*fromall_users;

Roles
Aroleisagroupofprivilegesassignedtoaname.Instead
ofgrantingeightprivilegestoauser,youcancreatearole
thatisassignedthoseeightprivileges,andthenassign
thatroletotheuser.

Creating a Role
➢Whenyoucreateanewrole,youcanassignitsome
privilegesorotherrolesthatwerepreviouslycreated.
➢TheSQLcommandusedtocreatearoleisCREATE
ROLE:
➢Inthefollowingexample,weconnectas
system/managertocreatearolecalledBasic1:
SQL> CREATE ROLE basic1;
Role created.

Granting Privileges and Roles to a Role
System/manager Arnold/terminator
Connect system/manager
Connected.
Create user arnoldidentified by
terminator
Connect arnold/terminator
Displayserror messages.
This example creates basic1 role.
SQL> CREATE ROLE basic1;
This example grants the
RESOURCE role to Basic1:
SQL> grant connect, resource to
basic1;
Grant operation successful.

Granting Privileges and Roles to a Role
System/manager arnold/terminator
SQL> grant basic1 to arnold;
Grant operation successful.
SQL> connect arnold/terminator
Connected.

Viewing the Roles of a User
➢TheUSER_ROLE_PRIVS commanddisplaysthe
rolesassignedtothecurrentuser:
➢SQL>select*fromuser_role_privs;
➢USERNAMEGRANTED_ROLE ADMDEFOS_
-----------------------------
ARNOLDBASIC1NOYESNO

Deleting a Role
➢Thecommandresponsibleforthedeletionofaroleis
DROPROLE.
➢Syntax:
DROPROLErole.
➢ThenextexampleremovestheBasic1role.
SQL>connectsystem/manager
Connected.
SQL>droprolebasic1;
Roleeliminated.
➢WhenwetrytoconnectasuserArnold,anerrorwill
occur,becausehehasnoassociatedprivilegeorrole: