Question: Create a table named 'course' with the fields: id , course _ name, dept _ name. Insert 6 records ( 2 for the English department,
Create a table named 'course' with the fields: id coursename, deptname.
Insert records for the English department, for the Math department, and for a different department of your choice
Create a function that returns the count of the number of courses in each department.
Query the number of courses in the Math department.
Please include explanations if possible.
Code is below:
create database chapter;
use chapter;
CREATE TABLE student
ID varchar
name varchar not null,
deptname varchar
totcred int;
INSERT INTO student id name, deptname, totcred values 'Peltier', 'Physics', ;
INSERT INTO student id name, deptname, totcred values 'Levy', 'Physics', ;
INSERT INTO student id name, deptname, totcred values 'Williams', 'Comp. Sci.;
INSERT INTO student id name, deptname, totcred values 'Sanchez', 'Music', ;
INSERT INTO student id name, deptname, totcred values 'Snow', 'Physics', ;
INSERT INTO student id name, deptname, totcred values 'Jacobs', 'Music', ;
SELECT FROM student;
DELIMITER $$
CREATE FUNCTION deptcount deptname varchar
RETURNS int
DETERMINISTIC
BEGIN
DECLARE dcount int;
SELECT count INTO dcount FROM student WHERE student.deptname deptname;
RETURN dcount;
END; $$
DELIMITER ;
SELECT deptcountMusic;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
