Relational database - student system As always please use speaker notes!
Student relational database system We are going to design tables for a system to contain student information. Think of this as the type of information that would be needed for a transcript. We need: Information about the student: idno, name and address, major etc. Information about the courses the students have taken including grade Tables that will allow us to get the name of the major and the name of the course
Student relational database system STUDENT TABLE: Student Idno - this is the primary key since all information relates to it Name Address Phone Social Security # - this is a candidate key since it could be used as a primary key Major code Date enrolled Other information related directly to the student This table has information about the student. All of it must be dependent on the primary key. Clearly we need major information about the major as well, but that cannot be stored on the student table because the name of the major and the chair of the department directly relate to the major code, not to the student idno. Therefore we need a major table. MAJOR TABLE: Major code - this is the primary key Major name Chair department
Student relational database system STUDENT COURSE TABLE: Student Idno Course code Primary key Semester course taken Grade Information about the courses the student has taken can not be kept on the STUDENT TABLE because they are a reoccurring group and thus break the rules of normalization. Essentially if we were to attempt to carry course information on the STUDENT TABLE we would have to determine how many slots we need (the maximum number of courses a student would be allowed to take). This is not practical and it definitely breaks the first normal form rule. The primary key has to be made up of more than one column/field because each student is allowed to take more than one course. The combination of student idno and course code and semester course was taken means that we will have a separate record for each time a course was taken by a student. COURSE TABLE: Course code - Primary key Course name Number credits We cannot keep the course name in the STUDENT COURSE TABLE because the course name directly relates to the course code. This breaks normalization rules. Practically speaking, we would not want to carry the course name in the STUDENT COURSE TABLE because if the course name changes we have to change it on any record. By carrying it on a separate COURSE TABLE, if the name changes we only have one place to enter that change.
SQL> create table student00 2 (studentidno varchar2(4), 3 name varchar2(20), 4 stadr varchar2(20), 5 city varchar2(20), 6 state varchar2(2), 7 zip varchar2(5), 8 phone varchar2(10), 9 ssnum varchar2(9), 10 majorcode varchar2(2), 11 enrolled date); Table created. SQL> create table major00 2 (majorcode varchar2(2), 3 majorname varchar2(30), 4 chair varchar2(20)); Table created. SQL> create table stucourse00 2 (studentidno varchar2(4), 3 coursecd varchar2(5), 4 semtaken varchar2(5), 5 grade varchar2(2)); Table created. SQL> create table course00 2 (coursecd varchar2(5), 3 coursename varchar2(30), 4 credits number(1)); Table created. Create tables
SQL> SELECT * FROM student00; STUD NAME STADR CITY ST ZIP PHONE SSNUM MA ENROLLED Stephen Daniels 345 Midland Ave Yonkers NY BU 09-SEP Jennifer Ames 12 Ave F Fall River MA CI 02-SEP Carl Hersey 12 Ave F Fall River MA BU 02-SEP Mary Stanton 156 West St Taunton MA CI 05-SEP John Richards 76 Main St Fall River MA CI 06-SEP-00 Oracle tables SQL> SELECT * FROM major00; MA MAJORNAME CHAIR BU Business Administration Adams CI Computer Information Systems Grocer
Oracle tables SQL> SELECT * FROM course00; COURS COURSENAME CREDITS CIS11 Intro to Computer Info Systems 3 CIS44 Internet User/Developer 3 CIS50 Oracle and SQL 3 CIS56 Visual Basic 3 MAN11 Intro to Management 3 MAR11 Marketing Principles 3 SQL> SELECT * FROM stucourse00 2 ORDER by studentidno; STUD COURS SEMTA GR CIS11 F2000 A MAR11 F2000 A 1111 CIS44 S2000 A 1212 CIS44 S2000 A 2222 CIS44 S2000 A 2222 MAN11 F2000 A CIS50 F2000 I 3333 CIS44 F2000 B 3333 CIS50 F2000 B CIS56 S2000 A-
SELECT SQL> SELECT student00.studentidno, name, student00.majorcode, majorname 2 FROM student00, major00 3 WHERE student00.majorcode = major00.majorcode; STUD NAME MA MAJORNAME Stephen Daniels BU Business Administration 2222 Carl Hersey BU Business Administration 1212 Jennifer Ames CI Computer Information Systems 2345 Mary Stanton CI Computer Information Systems 3333 John Richards CI Computer Information Systems SQL> SELECT * 2 FROM major00; MA MAJORNAME CHAIR BU Business Administration Adams CI Computer Information Systems Grocer SQL> SELECT studentidno, name, majorcode 2 FROM student00; STUD NAME MA Stephen Daniels BU 1212 Jennifer Ames CI 2222 Carl Hersey BU 2345 Mary Stanton CI 3333 John Richards CI The link between student00 and major00 is based on the majorcode. In the case of the first student, the BU links to the BU in the major00 table and pulls out the name.
SQL> SELECT stucourse00.studentidno, name, stucourse00.coursecd, coursename, grade 2 FROM student00, stucourse00, course00 3 WHERE stucourse00.studentidno = student00.studentidno AND stucourse00.coursecd = course00.coursecd; STUD NAME COURS COURSENAME GR Stephen Daniels CIS11 Intro to Computer Info Systems A Stephen Daniels CIS44 Internet User/Developer A 1111 Stephen Daniels MAR11 Marketing Principles A 1212 Jennifer Ames CIS44 Internet User/Developer A 2222 Carl Hersey CIS44 Internet User/Developer A 2222 Carl Hersey MAN11 Intro to Management A Mary Stanton CIS50 Oracle and SQL I 3333 John Richards CIS44 Internet User/Developer B 3333 John Richards CIS56 Visual Basic A John Richards CIS50 Oracle and SQL B+ 11 rows selected. SQL> SELECT studentidno, name 2 FROM student00; STUD NAME Stephen Daniels 1212 Jennifer Ames 2222 Carl Hersey 2345 Mary Stanton 3333 John Richards SQL> SELECT * 2 FROM stucourse00; STUD COURS SEMTA GR CIS11 F2000 A MAR11 F2000 A 1111 CIS44 S2000 A 1212 CIS44 S2000 A 2222 CIS44 S2000 A 2222 MAN11 F2000 A CIS44 F2000 B 3333 CIS50 F2000 B CIS56 S2000 A CIS50 F2000 I SQL> SELECT coursecd, coursename 2 FROM course00; COURS COURSENAME CIS11 Intro to Computer Info Systems CIS44 Internet User/Developer CIS50 Oracle and SQL CIS56 Visual Basic MAN11 Intro to Management MAR11 Marketing Principles
SQL> SELECT stucourse00.studentidno, name, student00.majorcode, majorname, 2 stucourse00.coursecd, coursename, grade 3 FROM stucourse00, student00, course00, major00 4 WHERE stucourse00.studentidno = student00.studentidno AND 5 student00.majorcode = major00.majorcode AND 6 stucourse00.coursecd = course00.coursecd; STUD NAME MA MAJORNAME COURS COURSENAME GR Stephen Daniels BU Business Administration CIS11 Intro to Computer Info Systems A Stephen Daniels BU Business Administration CIS44 Internet User/Developer A 1212 Jennifer Ames CI Computer Information Systems CIS44 Internet User/Developer A 2222 Carl Hersey BU Business Administration CIS44 Internet User/Developer A 3333 John Richards CI Computer Information Systems CIS44 Internet User/Developer B 2345 Mary Stanton CI Computer Information Systems CIS50 Oracle and SQL I 3333 John Richards CI Computer Information Systems CIS50 Oracle and SQL B John Richards CI Computer Information Systems CIS56 Visual Basic A Carl Hersey BU Business Administration MAN11 Intro to Management A Stephen Daniels BU Business Administration MAR11 Marketing Principles A SQL> SELECT * 2 FROM stucourse00; STUD COURS SEMTA GR CIS11 F2000 A MAR11 F2000 A 1111 CIS44 S2000 A 1212 CIS44 S2000 A 2222 CIS44 S2000 A 2222 MAN11 F2000 A CIS44 F2000 B 3333 CIS50 F2000 B CIS56 S2000 A CIS50 F2000 I SQL> SELECT studentidno, 2 name, majorcode 3 FROM student00; STUD NAME MA Stephen Daniels BU 1212 Jennifer Ames CI 2222 Carl Hersey BU 2345 Mary Stanton CI 3333 John Richards CI SQL> SELECT majorcode, 2 majorname 3 FROM major00; MA MAJORNAME BU Business Administration CI Computer Information Systems SQL> SELECT coursecd, coursename 2 FROM course00; COURS COURSENAME CIS11 Intro to Computer Info Systems CIS44 Internet User/Developer CIS50 Oracle and SQL CIS56 Visual Basic MAN11 Intro to Management MAR11 Marketing Principles