Answered step by step
Verified Expert Solution
Link Copied!

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, course_name, dept_name.
Insert 6 records (2 for the English department, 3 for the Math department, and 1 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 chapter5;
use chapter5;
CREATE TABLE student
(ID varchar(5),
name varchar(20) not null,
dept_name varchar(20),
tot_cred int);
INSERT INTO student (id, name, dept_name, tot_cred) values ('44553', 'Peltier', 'Physics', 56);
INSERT INTO student (id, name, dept_name, tot_cred) values ('45678', 'Levy', 'Physics', 46);
INSERT INTO student (id, name, dept_name, tot_cred) values ('54321', 'Williams', 'Comp. Sci.',54);
INSERT INTO student (id, name, dept_name, tot_cred) values ('55739', 'Sanchez', 'Music', 38);
INSERT INTO student (id, name, dept_name, tot_cred) values ('70557', 'Snow', 'Physics', 0);
INSERT INTO student (id, name, dept_name, tot_cred) values ('55740', 'Jacobs', 'Music', 42);
SELECT * FROM student;
DELIMITER $$
CREATE FUNCTION dept_count (dept_name varchar(20))
RETURNS int
DETERMINISTIC
BEGIN
DECLARE d_count int;
SELECT count(*) INTO d_count FROM student WHERE student.dept_name = dept_name;
RETURN (d_count);
END; $$
DELIMITER ;
SELECT dept_count('Music');

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions