DBMS 7 Exp
DBMS 7 Exp
Aim:
To create table and execute Data Control Language (DCL) and Transaction
Control Language (TCL).
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]');
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;
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:
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.