Dbms Darshan Report
Dbms Darshan Report
Dbms Darshan Report
By
2023-2024
1
LAB PROGRAM-1
Suppose a movie studio has several film fields. A crew
must be designated by a given studio as crew 1,crew 2
and so on. However other studios might use the same
designa>on for crews so the a@ribute key number is
not a key for crews. Movie studio holds the
informa>on like name branch and several loca>ons.
each crew holds informa>on like sector and strength.
ER-DIAGRAM
2
create table movie_studio
(sname varchar(25),
branch varchar(25),
primary key(sname));
desc movie_studio;
(sname varchar(25),
crew_no int,
sector int,
strength int,
primary key(sname,crew_no),
desc crew;
(sname varchar(25),
loca2on varchar(25),
primary key(sname,loca2on),
desc studio_loca2on;
3
Inser1ng values into the table
insert into movie_studio values
-> ('Gayatri','b1');
-> ('Maruthi','b2');
-> ('Krishna','b3');
('ionax','b4');
('Narthaki','b5');
-> ('Rockline','b6');
4
('Gayatri',1,2,20);
-> ('Maruthi',5,4,100);
-> ('ionax',3,6,40);
5
Queries lab-program -1
1)List all the movie_studios name which does not use a single crew
select sname from movie_studio
6
Write a procedure retrieve all crews used by specific studio.
DELIMITER //
BEGIN
SELECT c1.crew_no,c1.strength,c1.sector
FROM crew c1
WHERE m.sname=sname;
OPEN c;
read_loop:LOOP
IF done THEN
LEAVE read_loop;
END IF;
END LOOP;
CLOSE c;
END //
DELIMITER ;
7
Write a before insert trigger to check maximum number of crews to any
studio is limited to 5.
DELIMITER //
BEGIN
END IF;
END;
//
DELIMITER ;
8
9
Lab program -2
The production company is organised into
different studios. We store each studio's name
branch and location. Every studio must own
atleast one movie. We store each movie's title,
sensor number and year of production. Star
may act in any number of movies and we store
each actor's name and address.
ER-DIAGRAM
10
create table studios
desc studios;
desc movie;
desc actor;
11
mysql> create table owns
desc owns;
desc acts;
12
Inser1ng values into the table
insert into studios values
-> ('krishna','b4','Jayanagar');
13
mysql> insert into movie values
-> ('xyz',1,2002);
-> ('kantara',2,2005);
-> ('katera',3,2007);
-> ('kushi',4,2008);
-> ('leo',5,2012);
-> ('vikram',6,2015);
-> ('varisu',7,2017);
14
mysql> insert into actor values
-> ('DBoss','JayNagar');
-> ('Yash','GandiNagar');
15
mysql> insert into actor values
-> ('gayatri','xyz');
-> ('maruthi','xyz');
16
-> ('ionax','xyz');
-> ('krishna','xyz');
-> ('krishna','leo');
-> ('gayatri','vikram');
-> ('maruthi','varisu');
-> ('maruthi','katera');
-> ('krishna','katera');
-> ('maruthi','kantara');
17
mysql> insert into owns values
-> ('ionax','kantara');
-> ('ionax','kushi');
-> ('DBoss','katera');
-> ('DBoss','xyz');
-> ('Ramya','xyz');
18
Query OK, 1 row affected (0.01 sec)
-> ('Sudeep','xyz');
-> ('Yash','xyz');
-> ('Rashmika','xyz');
-> ('Rashmika','leo');
19
Queries for lab program-2
1)list all the studios of the movie ‘xyz’
select s.name,s.branch,s.loca2on
-> o.name=s.name;
20
2)list all the actors acted in the movie ‘xyz’
select a.aname
-> a.2tle=m.2tle;
Write a procedure to list all movies produced during the specific year.
DELIMITER //
BEGIN
SELECT 2tle
FROM movie
OPEN cur_2tle;
read_loop: LOOP
IF cur_done THEN
LEAVE read_loop;
END IF;
SELECT v_2tle;
21
END LOOP;
CLOSE cur_2tle;
END //
DELIMITER ;
Write a deleBon trigger, does not allow to deleBng current year movies.
DELIMITER //
BEGIN
END IF;
END //
DELIMITER ;
22
23
Lab-Program-3
A produc)on company is organised into different
studios. We store each studio's name, branch
and loca)on. Studio own any number of Cartoon
serials. We store cartoon studio's )tle, sensor
number and year of produc)on. Star may do
voices in any number of Cartoon serials. We store
each actor's name and address.
ER-DIAGRAM
24
create table cartoon studio
(sname varchar(25),
branch varchar(25),
loca2on varchar(25),
primary key(sname));
desc cartoon_studio;
(c2tle varchar(25),
25
sensor_no int,
yop int,
primary key(c2tle));
desc cartoons;
(aname varchar(25),
address varchar(25),
primary key(aname));
desc actors;
(sname varchar(25),
c2tle varchar(25),
primary key(sname,c2tle));
26
desc owning;
(aname varchar(25),
c2tle varchar(25),
primary key(aname,c2tle));
desc ac2ng;
('Gayatri','cnland','france');
('Maruthi','pogoland','India');
27
insert into cartoon_studio values
('Narthaki','Small contractor','Japan');
('Krishna','Small contractor','Japan');
('chota bheem',11,2003);
('roll no 21',13,2007);
('Doora',18,2014);
('Mickeymouse',12,2005);
('Balkrishna',17,2008);
28
InserBng values into actors table
insert into actors values
('JohyDep','london');
('james','USA');
('Tom kenny','England');
('chota bheem','JohyDep');
('chota bheem','james');
29
('chota bheem','Tom Kenny');
('Doora','Tom Kenny');
('Doora','james');
('','james');
('Balkrishna','james');
('Gayatri','chota bheem');
('ionax','Mickeymouse');
('Krishna','Doora');
('Maruthi','roll no 21');
30
Queries
1) Find the total number of actors do voice in cartoon serial xyz.
select count(*)
31
-> o.sname=s.sname;
32
IF cur_done THEN
LEAVE read_loop;
END IF;
SELECT v_title;
END LOOP;
CLOSE cur_title;
END//
DELIMITER ;
Write a deleBon trigger, does not allow to deleBng current year Cartoon-
Serials.
DELIMITER //
CREATE TRIGGER tr3
BEFORE DELETE ON CARTOON
FOR EACH ROW
BEGIN
DECLARE cur_year INT;
SET cur_year = YEAR(NOW());
IF OLD.yop = cur_year THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT='Cannot Delete';
END IF;
END//
DELIMITER ;
33
34
LAB-PROGRAM-4
Car marke)ng company wants to keep track of
marketed cars and their owners. Each car must
be associated with a single owner and the owner
may have any number of cars.We store car's
register number,model and colour. owner's
name, address and SSN. We also store date of
purchase of each car.
ER-DIAGRAM
35
create table car
(rno int,
model varchar(25),
color varchar(20),
ssn int,
dop date,
primary key(rno));
desc car;
(ssn int,
oname varchar(25),
address varchar(30),
primary key(ssn));
desc owners;
36
Inser1ng values into the table
mysql> insert into owners values
-> (67246,'Chinnu','JayaNagar');
-> (90163,'Rocky','JayaNagar');
-> (85412,'Pinky','RamNagar');
37
-> (49162,'Charu','Gokula Extension');
-> (81563,'Lamborgini','Black',64521,'2011-11-11');
-> (19742,'BMW','Silver',64521,'2013-01-06');
38
mysql> insert into car values
-> (27890,'Audi','White',64521,'2015-09-02');
-> (92356,'Innova','White',64521,'2003-06-05');
-> (76903,'Brezza','White',49162,'2004-08-12');
-> (18543,'Boleno','Black',49162,'2019-03-09');
-> (38236,'Bolero','Black',67246,'2016-06-07');
-> (94512,'Jaguar','White',85123,'2008-02-12');
-> (23546,'Toyota','White',85412,'2014-08-09');
39
Query OK, 1 row affected (0.01 sec)
-> (93451,'Jeep','White',85412,'2010-09-06');
-> (12890,'Ciaz','Black',90163,'2011-02-09');
-> (32189,'Honda','White',98154,'2013-02-04');
-> (67125,'Rolls-Royce','White',64521,'2000-03-03');
40
Queries for lab program-4
1)Find a person who owns highest number of cars
mysql> select o.oname,c.ssn,count(*)
41
2)Reterieve person’s and car’s informa6on purchased on the day
‘2011-11-11’
mysql> select o.oname,o.ssn,o.address,c.rno,c.model,c.color
-> c.ssn=o.ssn;
Write a procedure to list all cars and owner informaBon purchased during the
specific year.
DELIMITER //
BEGIN
42
DECLARE v_model VARCHAR(25);
OPEN cur_owner;
read_loop_owner: LOOP
IF done THEN
LEAVE read_loop_owner;
END IF;
END LOOP;
CLOSE cur_owner;
OPEN cur_car;
read_loop_car: LOOP
IF done THEN
LEAVE read_loop_car;
END IF;
43
SELECT CONCAT(v_rgno, ' ', v_model, ' ', v_color);
END LOOP;
CLOSE cur_car;
END //
DELIMITER ;
DELIMITER //
BEGIN
44
IF NEW.dop > cur_date THEN
END IF;
END //
DELIMITER ;
45
LAB-PROGRAM-5
46
create table dog_owner
47
Inser1ng values into the table
-> (89542,'Sachu','JayaNagar');
-> (54219,'Vamika','Bhadravathi');
48
mysql> insert into dog values
-> (32581,'Bunty','2017-03-02');
-> (89542,'Chinnu','2016-02-03');
-> (32581,'Zoozoo','2013-12-11');
-> (32581,'Pinky','2012-05-08');
-> (89542,'Charlie','2005-01-10');
-> (27845,'cooper','2011-10-12');
-> (27845,'twinkle','2010-10-10');
49
Query OK, 1 row affected (0.01 sec)
-> (27845,'teddy','2018-08-04');
-> (select *
50
2)List all the pets owned by a person ‘xyz’
mysql> select d.dname,d.ssn,d.dop
-> o.ssn=d.ssn;
Write a procedure to list all dogs and owner details purchased on the
specific date.
DELIMITER //
BEGIN
51
SELECT c1.rno, c1.model, c1.color
OPEN cur_owner;
read_loop_owner: LOOP
IF done THEN
LEAVE read_loop_owner;
END IF;
END LOOP;
CLOSE cur_owner;
OPEN cur_car;
read_loop_car: LOOP
IF done THEN
LEAVE read_loop_car;
END IF;
END LOOP;
CLOSE cur_car;
END //
DELIMITER ;
52
Write a trigger to check the constraint that the person can buy maximum
three pet dogs
DELIMITER //
BEGIN
53
SIGNAL SQLSTATE '45000'
END IF;
END //
DELIMITER ;
54