Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started