You are on page 1of 16

SQL QUERIES-3

TCL and DCL-COMMANDS


DCL

Grant and revoke


DCL
1. Go to start of your windows and type sql
command line.
2. connect
Username: system
Password: same as that of workspace
Create a table (say customer) and insert few tuple
into it.
Select * from customer;
DCL
3. Create a user:
create user lpu identified by 123;
4. Connect as lpu
You will get session permission denied
Again connect as system and assign permissions
grant create session to lpu;
Now try login as lpu
DCL
3. Create a user:
create user lpu identified by 123;
4. Connect as lpu
You will get session permission denied
Again connect as system and assign permissions
grant create session to lpu;
Now try login as lpu
DCL
5. As user lpu
select * from system.customer;
Permission denied
grant select, insert on customer to lpu;
Again login ad lpu
And try to insert data into table or delete a tuple
from table
DCL
As system user:
6. grant delete on customer to lpu;
Again connect as lpu and check

7. revoke insert on tablename from username;


TCL
1.Commit command
• Commit command
• Commit command is used to permanently save any
transaaction into database.
• Following is Commit command's syntax,
• commit;
• You cant rollback if you commit;
2.Rollback command

• Rollback command
• This command restores the database to last
commited state. It is also use with savepoint
command to jump to a savepoint in a transaction.
• Following is Rollback command's syntax,
• rollback to savepoint-name;
3. Savepoint command

• savepoint command is used to temporarily save a


transaction so that you can rollback to that point
whenever necessary.
• Following is savepoint command's syntax,
• savepoint savepoint-name;
• Savepoint A;
Example of Savepoint and Rollback

• Following is the class table,
ID NAME
1 abhi
2 adam
4 alex

• Lets use some SQL queries on the above table and


see the results.
1. INSERT into class values(5,'Rahul');
2. commit;
3. UPDATE class set name='abhijit' where id='5';
savepoint A;
4. INSERT into class values(6,'Chris');
5. savepoint B;
6. INSERT into class values(7,'Bravo');
7. savepoint C; SELECT * from class;
• The resultant table will look like,
Now ID NAME
• rollback to B; 1 abhi
2 adam
• SELECT * from class;
4 alex
• rollback to A; 5 abhijit
6 chris
• SELECT * from class;
7 bravo
• You will see how data is displayed
TCL
1. Open sql command line
2. connect
Username: system
Password:
Create a table.
create table s(id int, name varchar(15));
Insert data into it.
insert into s values(101, ‘a’);
insert into s values(102, ‘b’);
select * from s;
TCL
3. rollback
4. select * from s;
Add another record
2. Save Point
A point up till which rollback is to be done
Create save point:
savepoint A;
insert into s values(103, ‘c’);
insert into s values(104, ‘d’);
savepoint B;
TCL
insert into s values(105, ‘e’);
insert into s values(106, ‘f’);
savepoint C;
rollback to B;

commit: permanent changes are saved. Rollback does not effect.

You might also like