3
Deepak D. Upadhyay Enrollment No.: 160511201754 MCA Sem-3 13. Create application for professor to find out whether the professor is enrolled for university. If enrolled then returned class number associated with that professor. If professor is not a semester coordinator then give a suitable message. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Create Database: mysql> CREATE DATABASE clg; Query OK, 1 row affected (0.00 sec) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Use Database: mysql> USE clg; Database changed ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Create Table: mysql> CREATE TABLE profesor(pid int auto_increment primary key, pname varchar(20), enrol varchar(3), clss int(3), sem varchar(3)); Query OK, 0 rows affected (0.13 sec) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Insert Values in Table: mysql> INSERT INTO profesor(pname,enrol,clss,sem) VALUES ("Deepak","yes",3,"yes"),("Deepika","yes",2,"no"),("Dipesh","no",4,"yes"),("Diren","no",1,"no"); Query OK, 4 rows affected (0.01 sec) Records: 4 Duplicates: 0 Warnings: 0 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Inserted Values in Table: mysql> SELECT * FROM profesor; +-----+-----------+-------+------+------+ | pid | pname | enrol | clss | sem | +-----+-----------+-------+------+------+ | 1 | Deepak | yes | 3 | yes | | 2 | Deepika | yes | 2 | no | | 3 | Dipesh | no | 4 | yes | | 4 | Diren | no | 1 | no | +-----+-----------+-------+------+------+ 4 rows in set (0.02 sec) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

ADBMS (MySql) tiny project

Embed Size (px)

Citation preview

Page 1: ADBMS (MySql) tiny project

Deepak D. Upadhyay Enrollment No.: 160511201754

MCA Sem-3

13. Create application for professor to find out whether the professor is enrolled for university. If enrolled then returned class number associated with that professor. If professor is not a semester coordinator then give a suitable message. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ● Create Database: mysql> CREATE DATABASE clg; Query OK, 1 row affected (0.00 sec) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ● Use Database: mysql> USE clg; Database changed ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ● Create Table: mysql> CREATE TABLE profesor(pid int auto_increment primary key, pname varchar(20), enrol varchar(3), clss int(3), sem varchar(3)); Query OK, 0 rows affected (0.13 sec) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ● Insert Values in Table: mysql> INSERT INTO profesor(pname,enrol,clss,sem) VALUES ("Deepak","yes",3,"yes"),("Deepika","yes",2,"no"),("Dipesh","no",4,"yes"),("Diren","no",1,"no"); Query OK, 4 rows affected (0.01 sec) Records: 4 Duplicates: 0 Warnings: 0 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ● Inserted Values in Table: mysql> SELECT * FROM profesor; +-----+-----------+-------+------+------+ | pid | pname | enrol | clss | sem | +-----+-----------+-------+------+------+ | 1 | Deepak | yes | 3 | yes | | 2 | Deepika | yes | 2 | no | | 3 | Dipesh | no | 4 | yes | | 4 | Diren | no | 1 | no | +-----+-----------+-------+------+------+ 4 rows in set (0.02 sec) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Page 2: ADBMS (MySql) tiny project

Deepak D. Upadhyay Enrollment No.: 160511201754

MCA Sem-3

● Create Stored Procedure: mysql> DELIMITER // mysql> CREATE PROCEDURE Deepak(IN name varchar(20)) -> BEGIN -> DECLARE er varchar(3); -> DECLARE cl int(3) default 0; -> DECLARE se varchar(3); -> SET er=(SELECT enrol FROM profesor WHERE pname=name); -> SET cl=(SELECT clss FROM profesor WHERE pname=name); -> SET se=(SELECT sem FROM profesor WHERE pname=name); -> IF (er="yes") THEN -> SELECT CONCAT(name," is Enrolled in University") as Enrolled; -> IF (cl>0) THEN -> SELECT name as Profesor, cl as Class; -> IF (se="yes") THEN -> SELECT CONCAT(name," is Semester CoOrdinator") as CoOrdinator; -> ELSE -> SELECT CONCAT(name," is Not Semester CoOrdinator") as CoOrdinator; -> END IF; -> ELSE -> SELECT CONCAT(name," is Not Associated with Class") as Class; -> END IF; -> ELSE -> SELECT CONCAT(name," is Not Enrolled in University") as Enrolled; -> END IF; -> END // Query OK, 0 rows affected (0.05 sec) mysql> DELIMITER ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ● Execute the Stored Procedure: mysql> CALL Deepak("Deepak"); +-----------------------------------------+ | Enrolled | +-----------------------------------------+ | Deepak is Enrolled in University | +-----------------------------------------+ 1 row in set (0.03 sec) +-----------+--------+ | Profesor | Class | +-----------+--------+ | Deepak | 3 | +-----------+--------+

Page 3: ADBMS (MySql) tiny project

Deepak D. Upadhyay Enrollment No.: 160511201754

MCA Sem-3

1 row in set (0.03 sec) +-------------------------------------------+ | CoOrdinator | +-------------------------------------------+ | Deepak is Semester CoOrdinator | +-------------------------------------------+ 1 row in set (0.05 sec) Query OK, 0 rows affected (0.05 sec) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++