0% found this document useful (0 votes)
7 views7 pages

DBMS 7 Exp

DBMS 7 exp

Uploaded by

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

DBMS 7 Exp

DBMS 7 exp

Uploaded by

abinayadev04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Exp.

No: 7 DATA CONTROL LANGUAGE (DCL) AND


Date: TRANSACTION CONTROL LANGUAGE (TCL)

Aim:
To create table and execute Data Control Language (DCL) and Transaction
Control Language (TCL).

Data Control Language (DCL):


Data Control Language (DCL) is used to control access to data in the database.
DCL includes commands like GRANT and REVOKE, which are used to give or
take away permissions from users or roles. These commands help in managing
database security and controlling access to the database objects.

List of DCL commands:


1. Grant
2. Revoke
GRANT: This command gives user access privileges to the database.
REVOKE: This command withdraws the user’s access privileges given by
using the GRANT command.

Granting Privileges:
Create statement only creates a new user but does not grant any privileges to the
user account. Therefore, to grant privileges to a user account, the GRANT
statement is used.
Syntax:
GRANT privileges_names ON object TO user;

Parameters used:
Privileges_name: These are the access rights or privileges granted to the user.
Object: It is the name of the database object to which permissions are being
granted. In the case of granting privileges on a table, this would be the table
name.

User: It is the name of the user to whom the privileges would be granted.

Privileges: The privileges that can be granted to the users are listed below along
with the description:

Creation of tables:
use sample;
create table employee(id_no integer, ename varchar(30), dept varchar(30),
mob_no bigint, email_id varchar(50));
insert into employee values(430301, 'Tony', 'Software', 9343231123,
'[email protected]');
insert into employee values(430302, 'Steve', 'Finance', 9841284222,
'[email protected]');
insert into employee values(430306, 'Roger', 'Sales', 6354199921,
'[email protected]');
insert into employee values(430308, 'Stephen', 'Software', 7645190845,
'[email protected]');
insert into employee values(430310, 'Eric', 'Finance', 9840359756,
'[email protected]');

create table empdet(eid_no integer, empname varchar(30), salary bigint);


insert into empdet values(430302, 'Steve', 30000);
insert into empdet values(430308, 'Stephen', 35600);
insert into empdet values(430310, 'Eric', 50000);
Create user:
create user 'karthika'@localhost identified by 'tiger';

Granting privileges:
Granting SELECT Privilege to a User in a Table:
Query:
Grant select on sample.employee to 'karthika'@'localhost';
Output:
select * from sample.employee;

Granting more than one Privilege to a User in a Table:


Query:
Grant insert, update on sample.empdet to 'karthika'@'localhost';
Grant select on sample.empdet to 'karthika'@'localhost';
Output:
Granting all the Privilege to a User in a Table:
Query:
Grant all on sample.employee to 'karthika'@'localhost';
Output:

Revoking Privileges from a Table:


The Revoke statement is used to revoke some or all of the privileges which have
been granted to a user in the past.
Syntax:
REVOKE privileges ON object FROM user;

Parameters Used:

object:
It is the name of the database object from which permissions are being
revoked. In the case of revoking privileges from a table, this would be the table
name.
user:
It is the name of the user from whom the privileges are being revoked.
Privileges can be of the following values:
Different Ways of revoking privileges from a user:

Revoking SELECT Privilege to a User in a Table:


Query:
Revoke select on sample.empdet from 'karthika'@'localhost';
Output:

Revoking more than Privilege to a User in a Table:


Query:
Revoke insert, update on sample.empdet from 'karthika'@'localhost'
Output:

Revoking All the Privilege to a User in a Table:


Query:
Revoke all on sample.employee from 'karthika'@'localhost';
Output:

TRANSACTION CONTROL LANGUAGE (TCL):


Description:
Transaction Control Language (TCL) commands are used to manage
transactions in the database. These are used to manage the changes made by
DML statements. It allows it to be grouped together into logical transactions.
TCL commands:
1. Savepoint
2. Rollback
3. Commit
COMMIT:
Commit command is used to save all the transactions to the database.

Syntax:
commit;
Example:
start transaction;
delete from employee where id_no>430307;
commit;
select * from employee;

SAVEPOINT:
It is used to roll the transaction back to a certain point without rolling
back the entire transaction.

Syntax:
savepoint savepoint_name;

Example:
start transaction;
insert into empdet values(430311, 'Lesley', 40000);
savepoint detail1;
update empdet set salary=50000 where eid_no<430305;
savepoint deatil2;
ROLLBACK:
Rollback command is used to undo transactions that have not already
been saved to the database.

Syntax:
ROLLBACK TO SAVEPOINT_NAME;
Example:
rollback to detail1;
select * from empdet;

Result:
Thus, the Data Control Language (DCL) and Transaction Control Language
(TCL) commands were executed and output was verified successfully.

You might also like