KEMBAR78
RDBMS LAB Manual | PDF | Relational Database | Pl/Sql
0% found this document useful (0 votes)
613 views29 pages

RDBMS LAB Manual

Hiroor jodo3hbt9 riroo4jnjroof iroorj4JH4 rifiitjrn hjijchiir riot9j3nnfi8t rkgdti njigt7fufui vvuvivigit8cftj Iggy ng ugh the best friends with you have to me gf KO

Uploaded by

KetanPatel
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)
613 views29 pages

RDBMS LAB Manual

Hiroor jodo3hbt9 riroo4jnjroof iroorj4JH4 rifiitjrn hjijchiir riot9j3nnfi8t rkgdti njigt7fufui vvuvivigit8cftj Iggy ng ugh the best friends with you have to me gf KO

Uploaded by

KetanPatel
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/ 29

Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

Drashti Patel Page 1


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)
T. No Tutorial Page No.
1 Create the following tables using CREATE (DDL) 3
statement.
2 Apply the INSERT, SELECT (DML) on the created in 4
tutorial-1 statements to satisfy the following Use
aggregate function to retrieve summarized information
from table. Also Experiments various clauses (WHERE,
IN, NOT IN, BETWEEN …) to filter the information.
3 Experiment DDL, DML Statements on tables created in 10
tutotial-1
4 Identify the limitation of database design created in 12
tutorial-1. Make sure such limitation should not be there
in the new database of sales data to do so Use database
constraints on the following tables
5 Analyze the tables and extract information from one 17
table based on another table
6 Apply various database JOINS to discover information 18
from multiple tables for the followings.
7 Identify critical / secret information in tables. Create 20
different views to provide access to other users.
8 Create PL/SQL block for the followings to understand 22
its basic programming constructs:
9 Create reusable modules (function and stored procedure) 23
to perform specific task as mentioned below:
10 Experiment the followings to understand CURSOR in 26
Oracle:
11 Apply mechanism to maintain data consistency using 27
trigger. Create trigger that allow performing the
following operations on specified time.
12 In client-server architecture, we need to make sure that 28
every user has proper rights to access database tables.
Use GRANT & REVOKE commands to set proper
rights as mention below:

Drashti Patel Page 2


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)
Tutorial-1
Create the following tables using CREATE (DDL) statement.
1. create table branch (branch_name varchar2(15), branch_city
varchar2(10),assets number(10));

create table branch (branch_name varchar2(15), branch_city varchar2(10),assets
  number(10));

2. create table customer (customer_name varchar2(15), customer_street varchar2(
20), customer_city varchar2(10));

create table customer (customer_name varchar2(15), customer_street varchar2(20), cu
stomer_city varchar2(10));

3. create table account (account_number varchar2(10), branch_name varchar2(15)
,balance number(10));

create table account (account_number varchar2(10), branch_name varchar2(15),balan
ce number(10));

Drashti Patel Page 3


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

4. create table loan (loan_number varchar2(10),branch_name varchar2(15),amoun
t number(10));
create table loan (loan_number varchar2(10), branch_name varchar2(15),amount num
ber(10));

5. create table depositor (account_number varchar2(10), customer_name varchar2(
15));
create table depositor (account_number varchar2(10),customer_name varchar2(15));

6. create table borrower (customer_name varchar2(15), loan_number varchar2(10)
);
create table borrower (customer_name varchar2(15), loan_number varchar2(10));

Drashti Patel Page 4


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

Tutorial-2

Apply the INSERT, SELECT (DML) on the created in tutorial-1 statements to satisfy
the following Use aggregate function to retrieve summarized information from table.
Also Experiments various clauses (WHERE, IN, NOT IN, BETWEEN …) to filter the
information.

1. Insert records:
1) Insert records in branch table.

insert into branch values('SBI','Dehli',3000);
insert into branch values('SBM','Mysore',5000);
 insert into branch values('CYNDICATE','Mandya',2500);
 insert into branch values('CANARA','Mangalore',10000);
insert into branch values('ICICI','Mangalore',7500);

2) Insert records in customer table.

insert into customer values('Mohammed','V.V.Nagar','Delhi');
 insert into customer values('Punith','V.Puram','Mandya');
insert into customer values('Zeel','Yalahanka','Bangalore');
insert into customer values('Paul','R.T.Nagar','Bangalore');
 insert into customer values('Sachin','Newtown','Bangalore');

3) Insert records in account table.

insert into account values('A-100','SBI',10000);
insert into account values('A-101','SBM',20000);
insert into account values('A-103','CYNDICATE',50000);
insert into account values('A-104','CANARA',20000);
insert into account values('A-105','ICICI',50000);

4) Insert records in loan table.

insert into loan values(1000,'SBI',10000);
insert into loan values(2000,'SBM',20000);
insert into loan values(3000,'CYNDICATE',25000);
 insert into loan values(4000,'CANARA',36000);
insert into loan values(5000,'ICICI',60000);

Drashti Patel Page 5


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

5) Insert records in depositor table.

insert into depositor values('Mohammed',100);
 insert into depositor values('Punith',200);
 insert into depositor values('Zeel',300);
 insert into depositor values('Paul',400);
 insert into depositor values('Sachin',500);

6) Insert records in borrower table.

insert into borrower values('Mohammed',1000);
  insert into borrower values('Punith',2000);
  insert into borrower values('Zeel',3000);
  insert into borrower values('Paul',4000);
insert into borrower values('Sachin',5000);

2. View tables:

1) Select * from branch;

2) select * from customer;

3) Select * from account;

Drashti Patel Page 6


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

4) Select * from loan;

5) Select * from depositor;

6) Select * from borrower;

3. select account_no, balance from account;

Select account_number, balance from account;

4. select account_no from account where balance >1200;

select account_number from account where balance >1200;

Drashti Patel Page 7


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

5. select customer name from customer wherecustomer_city=’Rajkot’;


Select customer_name from customer where customer_city='Bangalore';

6. Select account_no from account where balance between 700 and900;


Select account_number from account where balance between 10000 and 12000;

7. Select * from customer order bycustomer_name;


Select * from customer order by customer_name;

8. select customer_name from customer where namelike=’r%’;


select customer_name from customer where customer_name like'Z%';

9. select * from customer where customer_city not in(‘amreli’,‘jamnagar’,‘valsad’);


select * from customer where customer_city not in('amreli','jamnagar','valsad');

Drashti Patel Page 8


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

10. select account_no from account where branch name in(‘kalavad road’,
‘mavdiroad’);
select account_number from account where branch_name in('SBM', 'SBI');

Drashti Patel Page 9


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

Tutorial-3

Experiment DDL, DML Statements on tables created in tutotial-1


1. Delete from account where account_no =‘B-101’;
Delete from account where account_number ='A-100';

2. delete from customer where customer_name like‘A%’;


delete from customer where customer_name like 'Z%';

3. delete from account where balance between 300 and500;


delete from account where balance between 300 and 500;

4. update table customer set customer_city = ‘Rajkot’ where customer name =


‘Dhaval’;
Update customer set customer_city = 'rajkot' where customer_name = 'Paul';

5. update table branch set assets = 800000 where branch_name = ‘gotriroad’;


update  branch set assets = 800000 where branch_name = 'SBM';

Drashti Patel Page 10


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

6. alter table customer modify (customer_streetvarchar2(30));


alter table customer modify (customer_street varchar2(30));

7. alter table customer add (telephone number(10));


alter table customer add (telephone number(10));

8. drop table borrower;


Drop table borrower;

9. rename ‘account’ to ‘account master’;


Rename account to account_master;

10. truncate table depositor table;


Truncate table depositor;

Drashti Patel Page 11


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

Tutorial: 4
Identify the limitation of database design created in tutorial-1. Make sure
such limitation should not be there in the new database of sales data to do so
Use database constraints on the following tables.

Table Creation:

1. create table customer_master(cust_no varchar2(10)primary key,product_no var
char2(6) references product_master, cust_nm varchar2(10)unique,cust_city varc
har2(20),cust_state varchar2(20),balance number(10));
create table customer_master(cust_no varchar2(10)primary key,product_no varchar2(6) refere
nces product_master, cust_nm varchar2(10)unique,cust_city varchar2(20),cust_state varchar2
(20),balance number(10));

2. create table product_master(product_no varchar2(6) primary key,name varchar
2(20) not null, description varchar2(50) not null, profite_percentage number(5,2)
, qty_on_hand number(8), reorder_level number(8) not null, sell_price number(8
,2) not null, cost_price number(8,2) not null);
create table product_master(product_no varchar2(6) primary key,name varchar2(20) n
ot null, description varchar2(50) not null, profite_percentage number(5,2), qty_on_ha
nd number(8), reorder_level number(8) not null, sell_price number(8,2) not null, cost
_price number(8,2) not null);

Drashti Patel Page 12


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

3. create table salesman_master(salesman_no varchar2(6)primary key,salesman_n
ame varchar2(20)not null, address varchar2(15)not null,city varchar2(10),state v
archar2(10),pincode number(8),sal_amt number(9,2)not null,remark varchar2(1
00));

create table salesman_master(salesman_no varchar2(6)primary key,salesman_na me 
varchar2(20)not null, address varchar2(15)not null,city varchar2(10),sta te varchar2
(10),pincode number(8),sal_amt number(9,2)not null,remark varcha r2(100));

4. create table sales_order(order_no varchar2(6) primary key,CHECK(order_no li
ke'O%'),cust_no varchar2(10) references customer_master,order_date date not 
null,salesman_no varchar2(6)references salesman_master,dely_type varchar2(1),
bill varchar2(1),dely_date date,order_status varchar2(15)CHECK(order_status i
n('in process','fulfilled','cancelled')));
create table sales_order(order_no varchar2(6) primary key,CHECK(order_no like'O
%'),cust_no varchar2(10) references customer_master,order_date date not null,salesm
an_no varchar2(6)references salesman_master,dely_type varchar2(1),bill varchar2(1),
dely_date date,order_status varchar2(15)CHECK(order_status in('in process','fulfilled'
,'cancelled')));

Drashti Patel Page 13


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

5. create table sales_order_details( order_no varchar2(6) references sales_order,pr
oduct_no varchar2(6) references product_master, qty_ordered number(8)not nul
l,qty_disp number(8)not null, product_rate number(10,2));
create table sales_order_details( order_no varchar2(6) references sales_order,product_
no varchar2(6) references product_master, qty_ordered number(8)not null,qty_disp nu
mber(8)not null, product_rate number(10,2));

Data Insertion:
1. Insert records in customer table.
Insert  into customer_master values('C001','P00001','Man','Surat','Gujarat',50000);
insert into customer_master values('C002','P00345','Zeel','Mumbai','Maharashtra',400
0);
insert into customer_master values('C003','P06734','Teju','Mumbai','Maharashtra',300
00);
insert into customer_master values('C004','P07865','Anil','Rajkot','Gujarat',12000);
insert into customer_master values('C005','P07868','Divay','Mumbai','Maharashtra',10
000);
select * from customer_master;

2. Insert records in product table.

insert into product_master values ('P00001','T-shirts',5,'Piece',200,300,400);
insert into product_master values('P00345','Shirts',6, 'Piece',150,500,600);
insert into product_master values('P0634','Cotton jeans',5,'Piece',100,600,800);
insert into product_master values('P07865','Jeans',5,'Piece',100,750,950);
Insert into product_master values('P07868','Trousers',2,'Piece',150,850,1000);

select * from product_master;

Drashti Patel Page 14


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

3. Insert records in salesman table.


insert into salesman_master values('S00001','Aman','miraroad','Mumbai','Maharastra',
400002,3000,'Good');
insert into salesman_master values('S00002','Omkar','rajhotel','Mumbai','Maharastra',0
0001,3000,'Good');
insert into salesman_master values('S00004','raj','punaroad','Mumbai','Maharastra',400
035,3000,'Good');
insert into salesman_master values('S00004','Ashish','hira road','Mumbai','Maharastra',
400044,3500,'Good');

select * from salesman_master;

4. Insert records in sales order table.


insert into sales_order(order_no,cust_no,order_date,salesman_no,dely_type,bill,dely_date,ord
er_status) values ('O19001','C001', DATE'2002-01-10','S00001','F','N', DATE'2002-07-
20','cancelled');
insert into sales_order(order_no,cust_no,order_date,salesman_no,dely_type,bill,dely_date,ord
er_status) values ('O19002','C002', DATE'2002-02-18,'S00001','P','N', DATE'2002-06-
20','cancelled');
insert into sales_order(order_no,cust_no,order_date,salesman_no,dely_type,bill,dely_date,ord
er_status) values ('O19003','C003', DATE'2002-02-18,'S00003','F','Y', DATE'2002-02-
20','cancelled');
insert into sales_order(order_no,cust_no,order_date,salesman_no,dely_type,bill,dely_date,ord
er_status) values ('O19004','C004', DATE'2002-04-03,'S00004','F','Y', DATE'2002-04-
07','cancelled');

Select * from sales order;

Drashti Patel Page 15


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

5. Insert records in sales order details table.

insert into sales_order_details values ('O19001','P00001',4,4,525);
insert into sales_order_details values ('O19002','P00345',2,1,8400);
insert into sales_order_details values ('O19003','P06734',2,1,5250);
insert into sales_order_details values ('O19003','P07865',10,0,525);
insert into sales_order_details values ('O19004','P07868',10,10,525);
select * from sales_order_details;

Drashti Patel Page 16


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

Tutorial-5
Analyze the tables and extract information from one table based on another table.

1. select product_no,description from product_master where product_no not in(select 
product_no from sales_order_details);
select product_no,description from product_master where product_no not in(select produ
ct_no from sales_order_details);

2. select cust_no,cust_city,balance from customer_master where cust_no in(select cust
_no from sales_order where order_no='O19003');

select cust_no,cust_city,balance from customer_master where cust_no in(select cust_no 
from sales_order where order_no='O19003');

3. select cust_no,cust_nm from customer_master where cust_no in(select cust_no fro
m sales_order where order_no in (select order_no from sales_order_details where p
roduct_no in(select product_no from product_master where description='Jeans')));
select cust_no,cust_nm from customer_master where cust_no in(select cust_no from sale
s_order where order_no in (select order_no from sales_order_details where product_no i
n(select product_no from product_master where description='Jeans')));

4. select cust_nm from customer_master where cust_no in(select cust_no from sales_o
rder where to_char(order_date,'mon-yy') > 'jul-09');

select cust_nm from customer_master where cust_no in(select cust_no from sales_order 
where to_char(order_date,'mon-yy') > 'jul-09');

Drashti Patel Page 17


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

Tutorial: 6

Apply various database JOINS to discover information from multiple tables for the
followings.

1. select sod.product_no,description from sales_order_details sod, sales_order so, p
roduct_master pm, customer_master cm where pm.product_no=sod.product_no 
and so.order_no=sod.order_no and cm.cust_no=so.cust_no and cm.cust_nm='An
il';
select sod.product_no,description from sales_order_details sod, sales_order so, produ
ct_master pm, customer_master cm where pm.product_no=sod.product_no and so.ord
er_no=sod.order_no and cm.cust_no=so.cust_no and cm.cust_nm='Anil';

2. select sales_order_details.product_no,order_no from sales_order_details,product
_master where sales_order_details.product_no = product_master.product_no an
d qty_ordered < 150 and description = 'Jeans';

select sales_order_details.product_no,order_no from sales_order_details,pro
duct_master where sales_order_details.product_no = product_master.product_n o a
nd qty_ ordered < 150 and description = 'Jeans';

3. select sod.product_no, description, sum(qty_disp) from sales_order_details sod, s
ales_order so, product_master pm where sod.product_no=pm.product_no and so
d.order_no=sod.order_no and to_char(order_date,'mon') = to_char(sysdate,'mo
n') group by description, sod.product_no;

select sod.product_no, description, sum(qty_disp) from sales_order_details sod, sales
_order so, product_master pm where sod.product_no=pm.product_no and sod.order_n
o=sod.order_no and to_char(order_date,'mon') = to_char(sysdate,'mon') group by desc
ription, sod.product_no;

Drashti Patel Page 18


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

4. select so.cust_no, sod.product_no, description, sum(qty_ordered) from sales_ord
er_details sod, product_master pm, sales_order so, customer_master cm where s
od.order_no=so.order_no and sod.product_no=pm.product_no and cm.cust_no=
so.cust_no group by so.cust_no, sod.product_no, description having so.cust_no='
C001' or so.cust_no='C002';

select so.cust_no, sod.product_no, description, sum(qty_ordered) from sales_order_de
tails sod, product_master pm, sales_order so, customer_master cm where sod.order_n
o=so.order_no and sod.product_no=pm.product_no and cm.cust_no=so.cust_no group 
by so.cust_no, sod.product_no, description having so.cust_no='C001' or so.cust_no='
C002';

Drashti Patel Page 19


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

Tutorial-7
Identify critical / secret information in tables. Create different views to
provide access to other users.

1. Create view vw_sales as select sales_order.order_no,order_date,order_status,pro
duct_no, qty_ordered from sales_order, sales_order_details.

Create view vw_sales as select sales_order.order_no,order_date,order_status,product_
no, qty_ordered from sales_order, sales_order_details;

select * from vw_sales;

2. Create view vw_prodas AS select product_no, description, sell_price from produ
ct_master;

Create view vw_prodas AS select product_no, description, sell_price from product_m
aster;

Select * from vw_prodas;

1) Insert into vw_prod values('P08','cap',200);
Insert into vw_prod values ('P08','cap',200);

Select * from vw_prod;

Drashti Patel Page 20


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

2) Update vw_prodas set sell_price=1600 where product_no='P06734';

Update vw_prodas set sell_price=1600 where product_no='P06734';

Select * from vw_prodas;

3) Delete from vw_prod where prod_no =‘P03’;

Delete from vw_prodas where product_no ='P07865';

3. Create view sels_deptas as select salesman_no, Salesman_name, City, Sal_amt fr
om Salesman_master;
Create view sels_deptas as select salesman_no, Salesman_name, City, Sal_amt from 
Salesman_master;

Select * from sels_deptas;

Drashti Patel Page 21


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

Tutorial: 8
Create PL/SQL block for the followings to understand its basic programming
constructs:

1. Write a PL/SQL block to calculate the area of a circle for a value of radius
varying from 3 to 7 store the radius and the corresponding values of
calculated area in an empty table named areas consisting of two columns
radius and area.
create table areas (radius number(5),area number(14,2));

declare
    pi constant number(4,2) :=3.14; 
    radius number(5);
    area number(14,2);
begin
   radius :=3;
   while radius <=7 loop
  area := pi * power(radius,2);
insert into areas values (radius, area); 
radius := radius + 1;
 
end loop;
end;

2. Write a PL/SQL block of code for inverting the number 5639 to9365
declare
     given_number varchar2(5) := '5639';
      str_length number(2);
      inverted_number varchar(5);
begin
     str_length := length(given_number);
      for cntr in reverse 1..str_length
loop

Drashti Patel Page 22


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)
     inverted_number := inverted_number || substr(given_number,cntr,1); 
    end loop;
dbms_output.put_line('The given number is '|| given_number); 
dbms_output.put_line('The inverted number is '|| inverted_number);
end;

Tutorial: 9
Create reusable modules (function and stored procedure) to perform specific task as
mentioned below:

Functions:
1. Write a function that finds whether the input parameters are a prime no.
declare
n number;              
i number;             
temp number;         
    
begin
n := 13;                  
i := 2;   
temp := 1;   
  for i in 2..n/2 
    loop 
        if mod(n, i) = 0 
        then
            temp := 0; 
            exit; 
        end if; 
    end loop; 
    
    if temp = 1 
    then
        dbms_output.put_line('true'); 
    else

Drashti Patel Page 23


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)
        dbms_output.put_line('false'); 
    end if; 
end;           

2. Write a function that accepts the order no from the user and displays the
product no and name of the product for that order no.
Create or replace function f_order_no(vorder_no IN varchar2)
Return number is 
dummy_order_no varchar2(6);
begin
select order_no into dummy_order_no from sales_order_details where o
rder_no = vorder_no; 
return 1;
Exception
    When No_Data_Found then return 0;
End;

Calling Function f_order_no in a PL / SQL code block

Declare
      Ans number(1);
Begin
     
     Ans:= f_order_no('&order_no');
     If ans = 0 then
     Insert into sale_order(order_no,product_no,qty_ordered,qty_disp) values ('O101','P2',20,5)
;
End if;
Commit; 
End;

Drashti Patel Page 24


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

Stored procedures:
1. Write a procedure which updates the field order_status from in
progress to fulfilled in the sales_order table.(dely_date + 5 days)

Create or replace procedure p1(dely_date in date, order_status in varchar2) IS
    mdate date;
    Status varchar2(20);
Begin
   Select dely_date into mdate from sales_order where dely_date + 5 = sysdate;
     Update sales_order set order_status = 'Fulfilled' where status ='cancelled';
End;

2. Calling the procedure P1 from PL/SQL block.

Declare
     mdate date;
     status varchar(20);
Begin
     dbms_output.put_line(mdate || '' || status);
    
End
 

Drashti Patel Page 25


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

Tutorial: 10
Experiment the followings to understand CURSOR in Oracle:

1. Declare cursor on account_master with SQL command used to define the


cursor with many options like.
a. Declare cursor
b. Open cursor
c. Fetch cursor
d. Close cursor
e. Delete cursor

Declare

CURSOR Crs_account IS Select account_no,branch_name,balance from account_master;
    a_no account_master.account_no%type;
    a_branch account_master.branch_name%type;
    a_balance account_master.balance%type;
   Begin
     OPEN Crs_account;
     dbms_output.put_line('Account_no         Branch_name              balance');
     dbms_output.put_line('---------         ----------                -------');

LOOP
     FETCH Crs_account into a_no,a_branch,a_balance; 
     EXIT when Crs_account%NOTFOUND;
     Dbms_output.put_line(a_no || '' || a_branch|| '' || a_balance); 
END LOOP;
CLOSE Crs_account;
 End;

Drashti Patel Page 26


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

Tutorial: 11
Apply mechanism to maintain data consistency using trigger. Create
trigger that allow to perform the following operations on specified time.

1. Write a database trigger before insert for each row on table sales_order not
allowing transactions for the order_date as Sundays.

Create or replace trigger check_date Before insert on sales_order for each row
 Declare
   s_date char(3);
   Begin
   s_date := to_char(sysdate,'day');
If  s_date in('SUNDAY') then
  raise_application_error(-20001,'Trnasation not allow on sunday');
 End if;
End;

Drashti Patel Page 27


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)

Tutorial: 12
In client-server architecture, we need to make sure that every user has
proper rights to access database tables. Use GRANT & REVOKE
commands to set proper rights as mention below:

1. Give the user Rahul permission only to view records in the table
sales_order and sales_order_details along with an option to further grant
permission on these tables to other users.

Grant select on sales_order, sales_order_details to rahul with grant option;

CREATE USER rahul IDENTIFIED BY rahul;

Grant select on sales_order, sales_order_details to rahul with admin option;

2. Use the Grant and Revoke Command by giving authority to Other User to
update, delete or insert into Table customer_master.

Grant insert, update, delete on customer_master to all;

Grant insert, update, delete on customer_master to rahul with admin option;

3. Take back all privileges given to the user Rahul on the table
customer_master.

Drashti Patel Page 28


Enrollment No:20SOECA21028 Semester: 1st MCA Subject: RDBMS (CE519)
Revoke all on customer_master from rahul;

Revoke all on customer_master from rahul;

Drashti Patel Page 29

You might also like