0% found this document useful (0 votes)
6 views1 page

Assignment 19

A MySQL database named 'assignment_19' is created with a table 'Student' that includes fields for id, name, address, and subject. Six student records are inserted into the table. A stored procedure 'CountStudentsBySubject' is defined to count students by their subject, and when called for 'CS', it returns a count of 2.

Uploaded by

Mrinmoy Pathak
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)
6 views1 page

Assignment 19

A MySQL database named 'assignment_19' is created with a table 'Student' that includes fields for id, name, address, and subject. Six student records are inserted into the table. A stored procedure 'CountStudentsBySubject' is defined to count students by their subject, and when called for 'CS', it returns a count of 2.

Uploaded by

Mrinmoy Pathak
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/ 1

mysql> use assignment_19;

Database changed
mysql>
mysql> CREATE TABLE Student (
-> id INT PRIMARY KEY,
-> name VARCHAR(255),
-> address VARCHAR(255),
-> subject VARCHAR(255)
-> );
Query OK, 0 rows affected (0.01 sec)

mysql>
mysql> INSERT INTO Student (id, name, address, subject)
-> VALUES
-> (1, 'Raj', 'Guwahati', 'CS'),
-> (2, 'Raja', 'Guwahati', 'CS'),
-> (3, 'Rajesh', 'Sibsagar', 'IT'),
-> (4, 'Diya', 'Jorhat', 'IT'),
-> (5, 'Nisha', 'Nagaon', 'ME'),
-> (6, 'Rajib', 'Sibsagar', 'EE');
Query OK, 6 rows affected (0.00 sec)
Records: 6 Duplicates: 0 Warnings: 0

mysql>
mysql> DELIMITER //
mysql> CREATE PROCEDURE CountStudentsBySubject(IN in_subject VARCHAR(255), OUT
out_count INT)
-> BEGIN
-> SELECT COUNT(*) INTO out_count
-> FROM Student
-> WHERE subject = in_subject;
-> END //
Query OK, 0 rows affected (0.00 sec)

mysql> DELIMITER ;
mysql>
mysql> CALL CountStudentsBySubject('CS', @count);
Query OK, 1 row affected (0.00 sec)

mysql> SELECT @count;


+--------+
| @count |
+--------+
| 2 |
+--------+
1 row in set (0.00 sec)

You might also like