0% found this document useful (0 votes)
121 views16 pages

2.DCL and TCL

1. The document discusses SQL commands including DCL (data control language) commands like GRANT and REVOKE to manage user permissions and TCL (transaction control language) commands like COMMIT, ROLLBACK, and SAVEPOINT to manage transactions. 2. It provides examples of using GRANT to assign permissions to a user, and REVOKE to remove permissions. It also demonstrates using SAVEPOINT to temporarily mark a point in a transaction, ROLLBACK to roll back to a savepoint, and COMMIT to permanently commit changes. 3. The examples create a table, insert and update records, set savepoints at different points, and use ROLLBACK and COMMIT to demonstrate how

Uploaded by

Aditya Anand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
121 views16 pages

2.DCL and TCL

1. The document discusses SQL commands including DCL (data control language) commands like GRANT and REVOKE to manage user permissions and TCL (transaction control language) commands like COMMIT, ROLLBACK, and SAVEPOINT to manage transactions. 2. It provides examples of using GRANT to assign permissions to a user, and REVOKE to remove permissions. It also demonstrates using SAVEPOINT to temporarily mark a point in a transaction, ROLLBACK to roll back to a savepoint, and COMMIT to permanently commit changes. 3. The examples create a table, insert and update records, set savepoints at different points, and use ROLLBACK and COMMIT to demonstrate how

Uploaded by

Aditya Anand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy