You are on page 1of 6

IV.

Data control Language ( DCL )

used to control the flow of information between users


i> Grant : used to give permissions on different database
objects to other users .

ii> Revoke : used to cancel the given permissions


from other users.

Permissions: Select , insert , update , delete , All

Scott : Giving Permissions


grant <permissions> on <table name> to
<user list> ;

grant all on emp to public;


grant insert , select on dept to user1,user2;
grant all on student to user1 with grant option;

Public : keyword
It represents all the users in server

With grant option : clause


It allows to give the permissions on shared object
to other users . scott --> user1 --> user2

user1: Using permissions


select * from scott.emp;
insert into scott.emp values (.....);
select * from scott.dept;
delete from scott.dept; -- error
select * from scott.student;
grant select,insert on scott.student to user2;

user2 : Using permissions


select * from scott.emp;
delete from scott.emp;
insert into scott.emp values (.....);
select * from scott.dept;
select * from scott.student;

#grant all on emp to public;


#grant insert , select on dept to user1,user2;
#grant all on student to user1 with grant option;

Scott : Removing permissions


#revoke all on emp from public;
-- revoke update, delete on emp from public;
#revoke insert , select on dept from user1,user2;
-- revoke insert , select on dept from user2;
#revoke all on student from user1;
---------------------------------------------------------------
Sharing Columns [ 8.0 ]
Supports to give permissions on selected columns.
Only insert and update permissions are allowed on
columns.
Delete and Select are not allowed on columns - They are treated as row level
operations.
Remove column content:
update emp set comm = null
where ename = 'MAHESH';

Scott :
grant insert (empno,ename,job,deptno) on emp
to user1;
grant update(fee) on student to user2;

user1 :
insert into scott.emp(empno,ename,job,deptno)
values(1001,'RAM','MANAGER',10);

user2 :
update scott.student set fee = fee + 1000
where roll = 101;

scott: Removing permissions


revoke insert on emp from user1;
revoke update on student from user2;
-------------------------------------------------------------
Creating New Users :

> show user --- scott

DBA Users :
sys/sysdba
system/manager

> connect sys as sysdba --> changing user to DBA


password : sysdba

> show user --- sys

create user <username> identified by <passwd>;


>create user ram identified by ram123;
>grant connect , resource to ram;

>grant connect ,resource to hari


identified by hari123;

>connect ram/ram123@oracle

>show user --- ram

In sys user :
>revoke connect,resource from ram;
>drop user hari cascade; -- removing user
Cascade : cut the links with other users

Unlocking user account: In sys user


> alter user scott account unlock;

Scott: Changing password


> Alter user scott identified by lion;

demobld7.sql -- Built_in file creates the Demo


tables in user login.
>start C:\oracle\ora92\oo4o\demobld7.sql
start -- executes the .sql file in oracle
-------------------------------------------------------------
System Tables :

* All_users
It Holds the list of users available in server.
> desc all_users
> select * from all_users;

* Tab -- Gives the list of Tables in user Login


> desc Tab
> select * from Tab;

* User_tables -- It gives the detailed information


about the tables created by user .
> desc user_tables
> select * from user_tables
where table_name = 'EMP' ;

* user_tab_columns -- It holds the details about


the columns in tables.
> desc user_tab_columns
> select * from user_tab_columns
where table_name = 'STUDENT' ;

> desc student


> select column_name, data_type from user_tab_columns
where table_name = 'STUDENT' ;

> select count(column_name) from user_tab_columns


where table_name = 'DEPT' ; -- 3

> select count(*) from dept; -- 4

* All_tab_privs_made -- It holds the list of permissions given


to other users.

* All_tab_privs_recd -- It holds the list of permissions


recieved from other users.

scott :
> desc all_tab_privs_made
> select * from all_tab_privs_made;

user1 / user2:
> desc all_tab_privs_recd
> select * from all_tab_privs_recd;
---------------------------------------------------------------
5. Transaction Control Langauge : ( TCL )

Used to control the changes made to the database.

TCL : Commit , Rollback , Savepoint

i> Commit : Used to save the changes made to the


database.
2 Types
a) Implicit Commit ( DDL ) : Applied by oracle automatically whenever DDL
statements are performed .

b) Explicit Commit ( DML ) : Provided by user


after performing DML statements on database
objects like Table , View , Synonym .

> insert / update / delete


> commit;

update emp set sal = sal + sal * .5


where empno = 7844;
commit;
---------------------------------------------------------------
Auto save options :
1. > update emp set sal = sal + 5000
where deptno = 30;
> exit

2. > insert
> update
> create ......... ( DDL )

* commit will release the resources in logical memory and improve the
performance of server.

> set autocommit on -- Automatically activates the commit stmt after every
DML stmt.
> delete from temp;
-- commit compleate
> set autocommit off ( default )
---------------------------------------------------------------
Rollback :
used to cancel the uncommited transactions( DML )
on database objects.
Not applicable for DDL stmts.

> delete from emp;


> select * from emp; -- no rows
> rollback;
> select * from emp; -- gives all rows

> delete from emp;


> select * from emp; -- no rows
> commit;
> select * from emp; -- no rows
> rollback;
> select * from emp; -- no rows
-----------------------------------
> insert -- 10 am
......
> update
> select
> insert
> update
> select
> update
> insert
> create -- 4 pm
> ...........
> delete emp; -- 5 pm
> rollback; -- cancels all the operations ( 4 - 5 )
----------------------------------------
> insert -- 10 am
......
> update
> select
> insert
> update
> select
> update
> insert
> select
> ...........
> delete emp; -- 5 pm
> rollback; -- cancels all the operations ( 10 - 5 )
-------------------------------------------------------------
Savepoint :
Used to identify the transactions performed previously.
Used to bookmark the transactions for further reference.
They are stored in Logical memory only.
Commit / Rollback will clear the savepoints.

> insert --- 1000 rows


> savepoint s1;
> update --- 500 rows
> savepoint s2;
> delete --- 100 rows
>
> rollback to savepoint s2; -- cancels delete stmt
> commit; -- Save insert and update stmts
-------------------------------------------------------------
> insert --- 1000 rows
>
> update --- 500 rows
>
> delete --- 100 rows
> rollback;
------------------------------------------------------------
* Truncate : ( DDL ) ==> Delete + commit
-----------------------
-- Removes all the rows from table and Save permanently to database.

-- It will release the resources alloted to data immediately . Performance is


improved .

Truncate removes all rows in 1 iteration


Delete removes 1 by 1 row

-- Where clause is not supported

truncate table emp;


desc emp

delete from emp;


commit;
desc emp

drop table emp;


desc emp -- error
-------------------------------------------------------------
create ,alter ,rename , drop , truncate -- DDL
-------------------------------------------------------------
Making a Copy of Table :

create table temp as select * from emp;


desc temp = desc emp
select * from temp;
drop table emp;
select * from temp;

create table employ as select empno ecode,


ename name, sal basic from emp;
desc employ
select * from employ;
ecode name basic

create table emp_pays as


select empno ecode,
sal basic , sal * .25 da , sal * .35 hra, sal * .15 pf,
sal + sal * .25 + sal *.35 - sal * .15 gross
from emp ;

desc emp_pays
select * from emp_pays;
ecode basic da hra pf gross

create table einfo as select * from emp


where 1 > 2; ---> copies only structure

desc einfo
select * from einfo; -- no rows

-- copying only rows


insert into einfo select * from emp; -- High level
Insert
select * from einfo;
update emp set sal = sal + 1000; -- High level
Update
delete from emp ; -- High level Delete

Note : Copied tables will not be changed whenever source table is


modified.
* High Level Insert , Update , Delete -- Codds Rule
* only Not null constraint will be copied.
-------------------------------------------------------------
Copying Table from other user :
scott : grant select on student to ram;
Ram :
create table student as select * from scott.student;
--------------------------------------------------------------

You might also like