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

ADS POE Questions

Uploaded by

Snehal Salokhe
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)
18 views7 pages

ADS POE Questions

Uploaded by

Snehal Salokhe
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

1. Implement two phase commit protocol.

2. From the following tables write a query to find the salesperson and customer who reside in
the same city. Return salesman, cust_name and city.

Perform Inner Join, Left Outer Join, Right Outer Join and Full Outer Join on following table.

Table: salesman

salesman_id name city commission


5001 James Hoog New York 0.15
5002 Nail Knite Paris 0.13
5005 Pit Alex London 0.11
5006 Mc Lyon Paris 0.14
5007 Paul Adam Rome 0.13
5003 Lauson Hen San Jose 0.12

Table: customer

customer_id cust_name city grade Salesman_id


3002 Nick Rimando New York 100 5001
3007 Brad Davis New York 200 5001
3005 Graham Zusi California 200 5002
3008 Julian Green London 300 5002
3004 Fabian Johnson Paris 300 5006
3009 Geoff Cameron Berlin 100 5003
3003 Jozy Altidor Moscow 200 5007
3001 Brad Guzan London 5005

3. From the following tables, write a SQL query to find all the orders issued by the salesman
‘Paul Adam’. Return ord_no, Purch_amt, ord_date, customer_id and salesman_id.
Table: salesman

salesman_id name city commission


5001 James Hoog New York 0.15
5002 Nail Knite Paris 0.13
5005 Pit Alex London 0.11
5006 Mc Lyon Paris 0.14
5007 Paul Adam Rome 0.13
5003 Lauson Hen San Jose 0.12
Table: orders

ord_no purch_amt ord_date customer_id salesman_id


70001 150.5 2012-10-25 3005 5002
70009 270.65 2012-09-11 3001 5005
70002 65.26 2012-04-17 3002 5001
70004 110.5 2012-05-02 3009 5003
70007 948.5 2012-11-20 3005 5002
70005 2400.6 2012-03-21 3007 5001
70008 250.45 2012-07-15 3002 5006
70011 75.29 2012-04-25 3003 5007

Select * from orders where salesman_id=( select salesman_id from


salesman where name =’paul Adam’);

4. Write a coed in PL/SQL to create a trigger that automatically updates a last_modified’


timestamp whenever a row ia a specific table is updated.
Solution:
CREATE TABLE Employee( employee
_id NUMBER PRIMARY KEY,
first_name VARCHAR2(50),
last_name VARCHAR2(50),
last_modified TIMESTAMP);

CREATE OR REPLACE TRIGGER update_last_modified


BRFORE UPDATE ON employee
FOR EACH ROW
BEGIN
:NEW.last_modified:=SYSTIMESTAMP;
END;
/
5. Implement Trigger

CREATE TABLE Geeks (


Id INT,
Name VARCHAR2(20),
Score INT
);
-- Insert into Geeks Table
INSERT INTO Geeks (Id, Name, Score) VALUES (1, 'Sam', 800);
INSERT INTO Geeks (Id, Name, Score) VALUES (2, 'Ram', 699);
INSERT INTO Geeks (Id, Name, Score) VALUES (3, 'Tom', 250);
INSERT INTO Geeks (Id, Name, Score) VALUES (4, 'Om', 350);
INSERT INTO Geeks (Id, Name, Score) VALUES (5, 'Jay', 750);

select * from Geeks;


CREATE TABLE Affect (
Id INT,
Name VARCHAR2(20),
Score INT
);
-- BEFORE INSERT trigger
CREATE OR REPLACE TRIGGER BEFORE_INSERT
BEFORE INSERT ON Geeks
FOR EACH ROW
BEGIN
INSERT INTO Affect (Id, Name, Score)
VALUES (:NEW.Id, :NEW.Name, :NEW.Score);
END;
/
INSERT INTO Geeks (Id, Name, Score) VALUES (6, 'Arjun', 500);
INSERT INTO Geeks (Id, Name, Score) VALUES (3, 'Ram', 250);
select * from Geeks;
select * from Affect;

6. MongoDB
db.createCollection("CSE")
db.CSE.insertOne({id:1,name:'Aarav'})
db.CSE.insertOne({id:2,name:'Parv'})
db.CSE.insertOne({id:3,name:'Vivan'})
db.CSE.insertOne({id:4,name:'Aarush'})
db.CSE.find()
db.CSE.update({name:'Parv'},{$set:{name:'Aarjav'}});
db.CSE.find()
db.CSE.deleteOne({name:'Aarush'})
db.CSE.find()
use blog
db.CSE.insertOne({id:1,name:'Aarav'})
db.CSE.find()

7. Use aggregate function and find FIRST,LAST,MIN,MAX, COUNT, SUM and AVG of commission
for following table.
Table: salesmen

salesman_id name city commission


5001 James Hoog New York 0.15
5002 Nail Knite Paris 0.13
5005 Pit Alex London 0.11
5006 Mc Lyon Paris 0.14
5007 Paul Adam Rome 0.13
5003 Lauson Hen San Jose 0.12

SELECT AVG(commission) AS AvgCommission FROM salesmen;


SELECT COUNT(*) AS NumSalesmen FROM salesmen;
SELECT FIRST(commission) AS FirstCommission FROM salesmen;
SELECT LAST(commission) AS LastCommission FROM salesmen;
SELECT MAX(commission) AS MaxCommission FROM salesmen;
SELECT MIN(commission) AS MinCommission FROM salesmen;
SELECT SUM(commission) AS SumCommission FROM salesmen;

8. Use scalar function UCASE, LCASE , MID, LEN, ROUND , NOW and FORMAT for the following
table.
Table : student
Roll_No name percentage
4 James Hoog 56.78
5 Nail Knite 70.12
7 Pit Alex 85.45
22 Mc Lyon 90.23
43 Paul Adam 34.56
6 Lauson Hen 76.45

SELECT UCASE(name) FROM student;


SELECT LCASE(name) FROM student;
SELECT MID(name,1,4) FROM student;
SELECT LENGTH(name) FROM student;
SELECT ROUND(marks,0) FROM student;
SELECT name, NOW() AS DateTime FROM student;
SELECT name, FORMAT(NOW(),’YYYY-MM-DD’)AS Date FROM student;

++++++++++++++++

Cursor
create table customers
( id int,
name varchar(20),
age int,
address varchar(20),
salary int
);
insert into customers (id,name,age,address,salary) values (1,'ram',34,'danoli',3000);
insert into customers (id,name,age,address,salary) values (2,'sham',30,'jaysingpur',3000);
insert into customers (id,name,age,address,salary) values (3,'lakhan',35,'kothali',7000);
insert into customers (id,name,age,address,salary) values (4,'ramesh',29,'shirol',5000);
insert into customers (id,name,age,address,salary) values (5,'seeta',26,'danoli',6000);
select * from customers;

DECLARE
total_rows number(2);
BEGIN
UPDATE customers
SET salary = salary + 5000;
IF sql%notfound THEN
dbms_output.put_line('no customers updated');
ELSIF sql%found THEN
total_rows := sql%rowcount;
dbms_output.put_line( total_rows || ' customers updated ');
END IF;
END;
/

DELIMITER $$

CREATE PROCEDURE update_customers()


BEGIN
DECLARE total_rows INT DEFAULT 0;

UPDATE customers
SET salary = salary + 5000;

SET total_rows = ROW_COUNT();

IF total_rows = 0 THEN
SELECT 'No customers updated' AS message;
ELSE
SELECT CONCAT(total_rows, ' customers updated') AS message;
END IF;

END $$

DELIMITER ;

select * from customers;

DECLARE
c_id customers.id%type;
c_name customers.name%type;
c_addr customers.address%type;
CURSOR c_customers is
SELECT id, name, address FROM customers;
BEGIN
OPEN c_customers;
LOOP
FETCH c_customers into c_id, c_name, c_addr;
EXIT WHEN c_customers%notfound;
dbms_output.put_line(c_id || ' ' || c_name || ' ' || c_addr);
END LOOP;
CLOSE c_customers;
END;
/

DELIMITER $$

CREATE PROCEDURE fetch_customers()


BEGIN

DECLARE c_id INT;


DECLARE c_name VARCHAR(255);
DECLARE c_addr VARCHAR(255);

DECLARE done INT DEFAULT FALSE;


DECLARE c_customers CURSOR FOR
SELECT id, name, address FROM customers;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;


OPEN c_customers;

read_loop: LOOP
FETCH c_customers INTO c_id, c_name, c_addr;

IF done THEN
LEAVE read_loop;
END IF;

SELECT CONCAT(c_id, ' ', c_name, ' ', c_addr) AS customer_info;


END LOOP;

CLOSE c_customers;

END $$

DELIMITER ;
Procedure
create table customers
( id int,
name varchar(20),
age int,
address varchar(20),
salary int
);

insert into customers (id,name,age,address,salary) values (1,'ram',34,'danoli',3000);


insert into customers (id,name,age,address,salary) values (2,'sham',30,'jaysingpur',3000);
insert into customers (id,name,age,address,salary) values (3,'lakhan',35,'kothali',7000);
insert into customers (id,name,age,address,salary) values (4,'ramesh',29,'shirol',5000);
insert into customers (id,name,age,address,salary) values (5,'seeta',26,'danoli',6000);
select * from customers;

create or replace procedure Test


as begin
update customers salary=5000 where address=’danoli’;
END;
/

EXEC Test;

select * from customers;

DELIMITER $$

CREATE PROCEDURE Test()


BEGIN
-- Update the salary to 5000 for customers with address 'danoli'
UPDATE customers
SET salary = 5000
WHERE address = 'danoli';
END $$

DELIMITER ;

You might also like