ISM4212 Case Study 3

advertisement
Module 7 – ISM4212 Case Study #3
Nathan Freeman
Professor Steve Mannion
Database & Physical Design
February 24, 2014
E-R Diagram
Instructors
Rooms
teach_id (PK)
name
phone
office (FK)
email
roomnumber (PK)
description
ClassSections
StudentClasses
Students
sect_id (PK)
teach_id (FK)
course_id (FK)
sem_id (FK)
room (FK)
sect_id (FK)
stud_id (FK)
grade
stud_id (PK)
name
address
phone
email
Courses
Semesters
course_id (PK)
coursename
credithours
sem_id (PK)
semesteryear
semestercode
SQL Code
CREATE DATABASE ISM4212_College;
GO
USE ISM4212_College;
CREATE TABLE Rooms
(roomnumber
VARCHAR(6)
description
VARCHAR(50)
NOT NULL
NULL);
PRIMARY KEY,
CREATE TABLE
(stud_id
name
address
phone
email
Students
INT
VARCHAR(30)
VARCHAR(30)
VARCHAR(20)
VARCHAR(30)
NOT
NOT
NOT
NOT
NOT
NULL
NULL,
NULL,
NULL,
NULL);
PRIMARY KEY,
CREATE TABLE
(teach_id
name
phone
office
email
Instructors
INT
VARCHAR(30)
VARCHAR(20)
VARCHAR(6)
VARCHAR(30)
NOT NULL
NOT NULL,
NOT NULL,
NULL
NOT NULL);
PRIMARY KEY,
CREATE TABLE Courses
(course_id
VARCHAR(8)
coursename
VARCHAR(50)
NOT NULL
NOT NULL);
PRIMARY KEY,
CREATE TABLE
(sem_id
semesteryear
semestercode
Semesters
INT
INT
VARCHAR(1)
NOT NULL
NOT NULL,
NOT NULL);
PRIMARY KEY,
CREATE TABLE
(sect_id
teach_id
course_id
sem_id
room
credithours
ClassSections
INT
INT
VARCHAR(8)
INT
VARCHAR(6)
INT
NOT
NOT
NOT
NOT
NOT
NOT
PRIMARY KEY,
REFERENCES Instructors (teach_id),
REFERENCES Courses (course_id),
REFERENCES Semesters (sem_id),
REFERENCES Rooms (roomnumber),
CREATE TABLE StudentClasses
(sect_id
INT
stud_id
INT
grade
INT
PRIMARY KEY (sect_id, stud_id));
NULL
NULL
NULL
NULL
NULL
NULL);
NOT NULL
NOT NULL
NULL,
REFERENCES Rooms (roomnumber),
REFERENCES ClassSections (sect_id),
REFERENCES Students (stud_id),
SQL Data Example
INSERT INTO Rooms (roomnumber, description)
VALUES
('A201', 'Chemistry Lab'),
('A202', 'Biology Lab'),
('B104', 'Computer Lab'),
('B105', 'Programming Lab'),
('B122', 'Political Science Auditorium'),
('B204', 'Dr. Einstein Office'),
('B205', 'Dr. Fizzle Office'),
('B206', 'Janitor Closet B2');
INSERT INTO Students (stud_id, name, address, phone, email)
VALUES
(10000001, 'Amanda Ammonia', '1000 Oak Street', '(904) 745-1234', 'aa@google.gov'),
(10000002, 'Claude Crumble', '2000 Pine Street', '(904) 745-2345', 'cc@msnlive.gov'),
(10000003, 'Fred Fumble', '3000 Magnolia Street', '(904) 745-3456', 'ff@aol.gov'),
(10000004, 'Vinny Vinegar', '4000 Elm Street', '(904) 745-4567', 'ii@yahoo.gov');
INSERT INTO Instructors (teach_id, name, phone, office, email)
VALUES
(10000001, 'Alberto Einstein', '(904) 724-1234', 'B204', 'ae@scc.edu'),
(10000002, 'Phil Fizzle', '(904) 724-2345', 'B205', 'pf@scc.edu'),
(10000003, 'Barack W. Bush', '(904) 724-3456', 'B206', 'bwb@scc.edu');
INSERT INTO Courses (course_id, coursename)
VALUES
('POS2473', 'Government by Walruses: For and Against'),
('POS2477', 'History of the Free-Soil Party'),
('CTS2437', 'Introduction to SQL Server'),
('ISM3013', 'Introduction to IT Management'),
('ISM4212', 'Database Design'),
('BSC2088', 'Florida Biology: Cockroach Anatomy'),
('CHM2590', 'Beryllium 101');
INSERT INTO Semesters (sem_id, semesteryear, semestercode)
VALUES
(1, 2013, 'A'),
(2, 2013, 'B'),
(3, 2013, 'C'),
(4, 2014, 'A'),
(5, 2014, 'B'),
(6, 2014, 'C');
INSERT INTO ClassSections
VALUES
(100001, 10000003,
(100002, 10000003,
(100003, 10000002,
(100004, 10000001,
(100005, 10000001,
(100006, 10000001,
(100007, 10000001,
(100008, 10000001,
(100009, 10000001,
(100010, 10000001,
(100011, 10000001,
(100012, 10000001,
(sect_id, teach_id, course_id, sem_id, room, credithours)
'POS2473',
'POS2473',
'POS2477',
'CTS2437',
'CTS2437',
'CTS2437',
'ISM3013',
'ISM4212',
'BSC2088',
'BSC2088',
'BSC2088',
'CHM2590',
3,
4,
4,
2,
3,
4,
3,
4,
2,
3,
4,
3,
'B122',
'B122',
'B122',
'B105',
'B105',
'B105',
'B104',
'B104',
'A202',
'A202',
'A202',
'A201',
3),
3),
3),
3),
3),
3),
3),
3),
4),
4),
4),
4);
INSERT INTO StudentClasses (sect_id, stud_id, grade)
VALUES
(100001, 10000001, 3),
(100011, 10000001, 4),
(100012, 10000001, 4),
(100001, 10000002, 2),
(100003, 10000002, 2),
(100006, 10000002, 2),
(100007, 10000003, 3),
(100008, 10000003, 4),
(100009, 10000003, 3),
(100005, 10000004, 2),
(100010, 10000004, 1),
(100012, 10000004, 2);
A sample transcript of a student’s grades:
SELECT s.name AS 'Student Name', coursename AS 'Course Name', (CONVERT(varchar(10),
semesteryear, 1) + semestercode) AS 'Term', grade AS 'Grade', credithours AS 'Credit Hours'
FROM StudentClasses sc
JOIN Students s ON sc.stud_id = s.stud_id
JOIN ClassSections cs ON sc.sect_id = cs.sect_id
JOIN Courses c ON cs.course_id = c.course_id
JOIN Semesters t ON cs.sem_id = t.sem_id
WHERE sc.stud_id = 10000001;
A query to find out which students are enrolled in a particular class:
SELECT s.name AS 'Student Name'
FROM StudentClasses sc
JOIN Students s ON sc.stud_id = s.stud_id
WHERE sc.sect_id = 100001;
Download