Sie sind auf Seite 1von 10

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:

This table has information about the student. All of it must be dependent on the primary key.

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 Clearly we need major Other information related directly to the student 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 MAJOR TABLE: student idno. Therefore we need a major table. Major code - this is the primary key Major name Chair department

Student relational database system

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.

STUDENT COURSE TABLE: Student Idno Course code Semester course taken Grade

Primary key

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.

Create tables

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.

Oracle tables
SQL> SELECT * FROM student00; STUD NAME STADR CITY ST ZIP PHONE SSNUM MA ---- -------------------- -------------------- -------------------- -- ----- ---------- --------- -ENROLLED --------1111 Stephen Daniels 345 Midland Ave Yonkers NY 03456 9145553456 036574678 BU 09-SEP-00 1212 Jennifer Ames 02-SEP-00 2222 Carl Hersey 02-SEP-00 2345 Mary Stanton 05-SEP-00 3333 John Richards 06-SEP-00 12 Ave F Fall River MA 02740 5085558343 034759850 CI

12 Ave F

Fall River

MA 02740 5085558343 045673945 BU

156 West St

Taunton

MA 04567 5085552090 035678090 CI

76 Main St

Fall River

MA 02456 5085556498 035656432 CI

SQL> SELECT * FROM major00; MA -BU CI MAJORNAME -----------------------------Business Administration Computer Information Systems CHAIR -------------------Adams Grocer

Oracle tables
SQL> SELECT * FROM stucourse00 2 ORDER by studentidno; STUD ---1111 1111 1111 1212 2222 2222 2345 3333 3333 3333 3333 SQL> SELECT * FROM course00; COURS ----CIS11 CIS44 CIS50 CIS56 MAN11 MAR11 COURSENAME CREDITS ------------------------------ --------Intro to Computer Info Systems 3 Internet User/Developer 3 Oracle and SQL 3 Visual Basic 3 Intro to Management 3 Marketing Principles 3 COURS ----CIS11 MAR11 CIS44 CIS44 CIS44 MAN11 CIS50 CIS44 CIS44 CIS50 CIS56 SEMTA ----F2000 F2000 S2000 S2000 S2000 F2000 F2000 F2000 F2000 F2000 S2000 GR -AA A A A AI B B B+ A-

SELECT
SQL> SELECT studentidno, name, majorcode 2 FROM student00; STUD ---1111 1212 2222 2345 3333 NAME -------------------Stephen Daniels Jennifer Ames Carl Hersey Mary Stanton John Richards MA -BU CI BU CI CI SQL> SELECT * 2 FROM major00; MA -BU CI MAJORNAME -----------------------------Business Administration Computer Information Systems CHAIR -----Adams Grocer

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 student00.studentidno, name, student00.majorcode, majorname 2 FROM student00, major00 3 WHERE student00.majorcode = major00.majorcode; STUD ---1111 2222 1212 2345 3333 NAME -------------------Stephen Daniels Carl Hersey Jennifer Ames Mary Stanton John Richards MA -BU BU CI CI CI MAJORNAME -----------------------------Business Administration Business Administration Computer Information Systems Computer Information Systems Computer Information Systems

SQL> SELECT * 2 FROM stucourse00; STUD ---1111 1111 1111 1212 2222 2222 3333 3333 3333 3333 2345 COURS ----CIS11 MAR11 CIS44 CIS44 CIS44 MAN11 CIS44 CIS44 CIS50 CIS56 CIS50 SEMTA ----F2000 F2000 S2000 S2000 S2000 F2000 F2000 F2000 F2000 S2000 F2000 GR -AA A A A AB B B+ AI

SQL> SELECT studentidno, name 2 FROM student00; STUD ---1111 1212 2222 2345 3333 NAME -------------------Stephen Daniels Jennifer Ames Carl Hersey Mary Stanton John Richards

SQL> SELECT coursecd, coursename 2 FROM course00; COURS ----CIS11 CIS44 CIS50 CIS56 MAN11 MAR11 COURSENAME -----------------------------Intro to Computer Info Systems Internet User/Developer Oracle and SQL Visual Basic Intro to Management Marketing Principles

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 ---1111 1111 1111 1212 2222 2222 2345 3333 3333 3333 3333 NAME -------------------Stephen Daniels Stephen Daniels Stephen Daniels Jennifer Ames Carl Hersey Carl Hersey Mary Stanton John Richards John Richards John Richards John Richards COURS ----CIS11 CIS44 MAR11 CIS44 CIS44 MAN11 CIS50 CIS44 CIS44 CIS56 CIS50 COURSENAME -----------------------------Intro to Computer Info Systems Internet User/Developer Marketing Principles Internet User/Developer Internet User/Developer Intro to Management Oracle and SQL Internet User/Developer Internet User/Developer Visual Basic Oracle and SQL GR -AA A A A AI B B AB+

11 rows selected.

SQL> 2 STUD ---1111 1111 1111 1212 2222 2222 3333 3333 3333 3333 2345

SELECT * FROM stucourse00; COURS SEMTA GR ----- ----- -CIS11 F2000 AMAR11 F2000 A CIS44 S2000 A CIS44 S2000 A CIS44 S2000 A MAN11 F2000 ACIS44 F2000 B CIS44 F2000 B CIS50 F2000 B+ CIS56 S2000 ACIS50 F2000 I

SQL> 2 3 STUD ---1111 1212 2222 2345 3333

SELECT studentidno, name, majorcode FROM student00; NAME -------------------Stephen Daniels Jennifer Ames Carl Hersey Mary Stanton John Richards

MA -BU CI BU CI CI

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 majorcode, 2 majorname 3 FROM major00; MA MAJORNAME -- ----------------------------BU Business Administration CI Computer Information Systems

SQL> 2 3 4 5 6

SELECT stucourse00.studentidno, name, student00.majorcode, majorname, stucourse00.coursecd, coursename, grade FROM stucourse00, student00, course00, major00 WHERE stucourse00.studentidno = student00.studentidno AND student00.majorcode = major00.majorcode AND stucourse00.coursecd = course00.coursecd;
STUD ---1111 1111 1212 2222 3333 3333 2345 3333 3333 2222 1111 NAME -------------------Stephen Daniels Stephen Daniels Jennifer Ames Carl Hersey John Richards John Richards Mary Stanton John Richards John Richards Carl Hersey Stephen Daniels MA -BU BU CI BU CI CI CI CI CI BU BU MAJORNAME -----------------------------Business Administration Business Administration Computer Information Systems Business Administration Computer Information Systems Computer Information Systems Computer Information Systems Computer Information Systems Computer Information Systems Business Administration Business Administration COURS ----CIS11 CIS44 CIS44 CIS44 CIS44 CIS44 CIS50 CIS50 CIS56 MAN11 MAR11 COURSENAME -----------------------------Intro to Computer Info Systems Internet User/Developer Internet User/Developer Internet User/Developer Internet User/Developer Internet User/Developer Oracle and SQL Oracle and SQL Visual Basic Intro to Management Marketing Principles GR -AA A A B B I B+ AAA

Das könnte Ihnen auch gefallen