0% found this document useful (0 votes)
3 views2 pages

DBMSPG 5

The document outlines a series of MySQL commands to manage an 'Employee' table, including dropping the table, creating it, and inserting employee records. It also details the creation of a stored procedure that utilizes a cursor to fetch and display employee details. Finally, the procedure is called to show the information of all employees in the table.

Uploaded by

amhegde4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

DBMSPG 5

The document outlines a series of MySQL commands to manage an 'Employee' table, including dropping the table, creating it, and inserting employee records. It also details the creation of a stored procedure that utilizes a cursor to fetch and display employee details. Finally, the procedure is called to show the information of all employees in the table.

Uploaded by

amhegde4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

mysql> use pg5;

Database changed
mysql> drop table employee;
Query OK, 0 rows affected (0.02 sec)

mysql> -- Create table and insert data


mysql> CREATE TABLE Employee (
-> E_id INT PRIMARY KEY,
-> E_name VARCHAR(100),
-> Age INT,
-> Salary INT
-> );
Query OK, 0 rows affected (0.03 sec)

mysql>
mysql> INSERT INTO Employee VALUES (1, 'Braham Kumar', 30, 50000);
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO Employee VALUES (2, 'Shubham', 32, 55000);


Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO Employee VALUES (3, 'Bikash', 28, 48000);


Query OK, 1 row affected (0.00 sec)

mysql>
mysql> -- Create stored procedure using a cursor
mysql> DELIMITER $$
mysql>
mysql> CREATE PROCEDURE ShowEmployeeDetails()
-> BEGIN
-> DECLARE v_E_id INT;
-> DECLARE v_E_name VARCHAR(100);
-> DECLARE v_Age INT;
-> DECLARE v_Salary INT;
-> DECLARE done INT DEFAULT 0;
->
-> DECLARE employee_cursor CURSOR FOR
-> SELECT E_id, E_name, Age, Salary FROM Employee;
->
-> DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
->
-> OPEN employee_cursor;
->
-> read_loop: LOOP
-> FETCH employee_cursor INTO v_E_id, v_E_name, v_Age, v_Salary;
-> IF done THEN
-> LEAVE read_loop;
-> END IF;
->
-> SELECT CONCAT('E_id: ', v_E_id, ', E_name: ', v_E_name, ', Age: ',
v_Age, ', Salary: ', v_Salary) AS EmployeeInfo;
-> END LOOP;
->
-> CLOSE employee_cursor;
-> END$$
Query OK, 0 rows affected (0.02 sec)

mysql>
mysql> DELIMITER ;
mysql>
mysql> -- Call the procedure
mysql> CALL ShowEmployeeDetails();
+-------------------------------------------------------+
| EmployeeInfo |
+-------------------------------------------------------+
| E_id: 1, E_name: Braham Kumar, Age: 30, Salary: 50000 |
+-------------------------------------------------------+
1 row in set (0.00 sec)

+--------------------------------------------------+
| EmployeeInfo |
+--------------------------------------------------+
| E_id: 2, E_name: Shubham, Age: 32, Salary: 55000 |
+--------------------------------------------------+
1 row in set (0.01 sec)

+-------------------------------------------------+
| EmployeeInfo |
+-------------------------------------------------+
| E_id: 3, E_name: Bikash, Age: 28, Salary: 48000 |
+-------------------------------------------------+
1 row in set (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

mysql>

You might also like