uts database
DESCRIPTION
UTS DATABASE. Chris Zaharia. The Domain – UTS. The Domain – UTS. Based on the UTS Database that contains information on courses and subjects Focuses especially on categorising courses under structures which contain subjects - PowerPoint PPT PresentationTRANSCRIPT
UTS DATABASEUTS DATABASEChris ZahariaChris Zaharia
The Domain – UTSThe Domain – UTS
The Domain – UTSThe Domain – UTS
Based on the UTS Database that contains Based on the UTS Database that contains information on information on coursescourses and and subjectssubjects
Focuses especially on categorising Focuses especially on categorising courses under courses under structuresstructures which contain which contain subjects subjects i.e. A course can have core, major etc i.e. A course can have core, major etc structures that have a number of subjects structures that have a number of subjects in each structure categoryin each structure category
http://www.uts.edu.au
Entity Relationship DiagramEntity Relationship Diagram
SubjectSubjectIDSubjectNameSubjectDescSubjectGradCPFacultySubjectEFTSL *
CourseCourseIDCourseNameCourseDescCourseGrad CourseAwardCourseAward2 CRICOSCodeCommSupport LoadCP CourseEFTSLFacRespFacCollLocation
SubjectStructureSubjectID *StructureID *
CourseUACCode UACNumberCourseID *UACType
SubjectRequisiteSubjectID *ReqSubject *
SubjectFeeSubjectEFTSLFeeComPriceFeeDomPrice
CourseStructureCourseID *StructureID *StructureCP
CourseStructureChoiceStructureID *StructureChoiceID *
SubjectStructureChoiceSubjectID *StructureChoiceID *
StructureStructuretIDStructureType
StructureChoiceStructureChoiceIDStructureChoiceName
Course
CourseUACCode SubjectRequisite
Subject
SubjectStructureChoice
CourseStructureChoice
SubjectChoice
CourseStructure
SubjectStructure
Structure SubjectFee
One-to-many RelationshipOne-to-many RelationshipSubjectIDSubjectID SubjectNameSubjectName SubjectSubject
EFTSLEFTSL
2210722107 Accounting for BusinessAccounting for Business 0.1250.125
3125731257 Information System Information System Development Development MethodologiesMethodologies
0.1250.125
3127131271 Database FundamentalsDatabase Fundamentals 0.1250.125
7011370113 Legal Process and HistoryLegal Process and History 0.2080.208
SubjectEFTSLSubjectEFTSL FeeComPriceFeeComPrice FeeDomPriceFeeDomPrice
0.0830.083 694.42694.42 16481648
0.1250.125 889.75889.75 22802280
0.2080.208 1736.041736.04 41204120
0.250.25 1779.51779.5 49204920
Primary Key
Primary Key
Foreign Key
Both tables have a one-to-many relationship Linked by a foreign key
Table 1 - Subject
Table 1 - SubjectFee
One-to-many RelationshipOne-to-many Relationship
SubjectSubjectSubjectID
SubjectName
SubjectDesc
SubjectGrad
CP
Faculty
SubjectEFTSL *
SubjectFeeSubjectFeeSubjectEFTSL
FeeComPrice
FeeDomPriceHas
ERDERD
Many-to-many RelationshipMany-to-many Relationship
SubjectIDSubjectID StructureIDStructureID
3127031270 STM90651STM90651
3127131271 STM90651STM90651
3128031280 CBK90781CBK90781
3128031280 CBK90782CBK90782
StructureIDStructureID StructureTypeStructureType
CBK90781CBK90781 MajorMajor
CBK90782CBK90782 Major/Two Major/Two Submajors/ElectivesSubmajors/Electives
STM90651STM90651 CoreCore
SubjectIDSubjectID SubjectNameSubjectName
3127031270 Networking Networking EssentialsEssentials
3127131271 Database Database FundamentalsFundamentals
3128031280 Strategic IT Strategic IT ProjectProject
PrimaryKey
PrimaryKey
ForeignKey
ForeignKey
Primary Key
Table 1 - Subject Table 2 - StructureTable 3 - SubjectStructure
Both one-to-many pairedRelationships (T1,T3; T2,T3)Creates a many-to-manyrelationship
Table 1 and Table 2Primary keys are foreignKeys in table 3
Many-to-many RelationshipMany-to-many Relationship
ERDERDSubjectSubjectSubjectID
SubjectName
SubjectDesc
SubjectGrad
CP
Faculty
SubjectEFTSL *
StructureStructureStructuretID
StructureType
SubjectStructureSubjectStructure
SubjectID *
StructureID *Part of Contains
QueriesQueries
1. Show all undergraduate courses.1. Show all undergraduate courses.SELECT courseID, courseName, courseGrad SELECT courseID, courseName, courseGrad
FROM Zaharia_UTS_Course FROM Zaharia_UTS_Course
WHERE courseGrad = 'Undergraduate';WHERE courseGrad = 'Undergraduate';
CourseID CourseID CourseName CourseName CourseGradCourseGrad
C10026 C10026 Bachelor of BusinessBachelor of Business UndergraduateUndergraduate
C10148 C10148 Bachelor of Science in Information Bachelor of Science in Information Technology Technology
UndergraduateUndergraduate
C10219 C10219 Bachelor of Business Bachelor of Bachelor of Business Bachelor of Science in Information Technology Science in Information Technology
UndergraduateUndergraduate
QueriesQueries
2. Show all subjects with requisites and 2. Show all subjects with requisites and display their requisites.display their requisites.
SELECT subjectID, subjectName, reqSubjectSELECT subjectID, subjectName, reqSubject
FROM Zaharia_UTS_Subject NATURAL JOIN Zaharia_UTS_SubjectRequisite;FROM Zaharia_UTS_Subject NATURAL JOIN Zaharia_UTS_SubjectRequisite;
SubjectIDSubjectID SubjectName SubjectName ReqSubjectReqSubject
22320 22320 Accounting for Business CombinationsAccounting for Business Combinations 2210722107
31257 31257 Information System Development Methodologies Information System Development Methodologies 3127031270
31269 31269 Business Requirements Modelling Business Requirements Modelling 3126631266
31272 31272 Project Management and the Professional Project Management and the Professional 3126931269
3128031280 Strategic IT ProjectStrategic IT Project 3125731257
3128031280 Strategic IT ProjectStrategic IT Project 3127231272
3128031280 Strategic IT ProjectStrategic IT Project 3127631276
QueriesQueries
3. Show subjects along with their structure 3. Show subjects along with their structure types.types.
SELECT SubjectID, Zaharia_UTS_Structure.StructureID, StructureTypeSELECT SubjectID, Zaharia_UTS_Structure.StructureID, StructureTypeFROM Zaharia_UTS_Structure, Zaharia_UTS_SubjectStructureFROM Zaharia_UTS_Structure, Zaharia_UTS_SubjectStructureWHERE Zaharia_UTS_Structure.StructureID = WHERE Zaharia_UTS_Structure.StructureID =
Zaharia_UTS_SubjectStructure.StructureID;Zaharia_UTS_SubjectStructure.StructureID;
QueriesQueriesSubjectID SubjectID StructureID StructureID StructureType StructureType
22107 22107 STM90273 STM90273 Core Core
22320 22320 CBK90169 CBK90169 MajorMajor
22320 22320 CBK90170 CBK90170 Major/Two Submajors/Submajor + Four Electives Major/Two Submajors/Submajor + Four Electives
31257 31257 CBK90781 CBK90781 MajorMajor
31257 31257 CBK90782 CBK90782 Major/Two Submajors/ElectivesMajor/Two Submajors/Electives
31266 31266 STM90651STM90651 Core Core
31269 31269 STM90651STM90651 Core Core
31270 31270 STM90651STM90651 Core Core
31271 31271 STM90651STM90651 Core Core
31272 31272 STM90651STM90651 Core Core
31276 31276 CBK90781CBK90781 Major Major
31276 31276 CBK90782CBK90782 Major/Two Submajors/Electives Major/Two Submajors/Electives
31280 31280 CBK90781CBK90781 Major Major
31280 31280 CBK90782CBK90782 Major/Two Submajors/Electives Major/Two Submajors/Electives
70113 70113 CBK90170CBK90170 Major/Two Submajors/Submajor + Four ElectivesMajor/Two Submajors/Submajor + Four Electives
70113 70113 CBK90782CBK90782 Major/Two Submajors/Electives Major/Two Submajors/Electives
QueriesQueries
4. Show the average of the Commonwealth 4. Show the average of the Commonwealth and Domestic fee price for each subject and Domestic fee price for each subject whose fee average is over $5000whose fee average is over $5000
SELECT subjectID, avg(FeeComPrice + FeeDomPrice) AS SELECT subjectID, avg(FeeComPrice + FeeDomPrice) AS Average_SubjectPriceAverage_SubjectPrice
FROM Zaharia_UTS_SubjectFee NATURAL JOIN Zaharia_UTS_SubjectFROM Zaharia_UTS_SubjectFee NATURAL JOIN Zaharia_UTS_Subject
GROUP BY subjectIDGROUP BY subjectID
HAVING avg(FeeComPrice + FeeDomPrice) > 5000;HAVING avg(FeeComPrice + FeeDomPrice) > 5000;
SubjectIDSubjectID Average_SubjectPriceAverage_SubjectPrice
7011370113 5856.045856.04
QueriesQueries
5. Show all core subjects that are newer 5. Show all core subjects that are newer then the very first core subject.then the very first core subject.
SELECT subjectIDSELECT subjectID
FROM Zaharia_UTS_SubjectStructure NATURAL JOIN FROM Zaharia_UTS_SubjectStructure NATURAL JOIN Zaharia_UTS_StructureZaharia_UTS_Structure
WHERE structureType = 'Core'WHERE structureType = 'Core'
AND subjectID > (AND subjectID > (
SELECT min(subjectID) SELECT min(subjectID)
FROM Zaharia_UTS_SubjectStructureFROM Zaharia_UTS_SubjectStructure
););
SubjectIDSubjectID
3126631266
3126931269
3127031270
3127131271
3127231272
QueriesQueries
6. Show all courses that share the same 6. Show all courses that share the same graduation status as course C10219 graduation status as course C10219 (BBus BScIT).(BBus BScIT).
SELECT c1.courseIDSELECT c1.courseID
FROM Zaharia_UTS_Course c1, Zaharia_UTS_Course C2FROM Zaharia_UTS_Course c1, Zaharia_UTS_Course C2
WHERE c1.courseGrad = c2.courseGradWHERE c1.courseGrad = c2.courseGrad
AND c2.courseID = 'C10219'AND c2.courseID = 'C10219'
AND c1.courseID <> 'C10219';AND c1.courseID <> 'C10219';CourseIDCourseID
C10026C10026
C10148C10148
CHECK Constraint ExamplesCHECK Constraint Examples
• Check for graduation statusCheck for graduation status
CONSTRAINT Zaharia_UTS_Course_CourseGradCONSTRAINT Zaharia_UTS_Course_CourseGrad
CHECKCHECK (CourseGrad IN ( (CourseGrad IN (
'Undergraduate', 'Postgraduate')),'Undergraduate', 'Postgraduate')),
• Check value of Course EFTSLCheck value of Course EFTSL
CONSTRAINT Zaharia_UTS_Course_CourseEFTSL CONSTRAINT Zaharia_UTS_Course_CourseEFTSL
CHECKCHECK (CourseEFTSL BETWEEN 0.5 AND 7) (CourseEFTSL BETWEEN 0.5 AND 7)
CHECK Constraint ExamplesCHECK Constraint Examples
• Check for Faculty ResponsibleCheck for Faculty Responsible
CONSTRAINT Zaharia_UTS_Course_FacResp CONSTRAINT Zaharia_UTS_Course_FacResp CHECKCHECK (FacResp IN ( (FacResp IN (
'Business','Business','Design, Architecture and Building','Design, Architecture and Building','Education','Education','Engineering','Engineering','Humanities','Humanities','Information Technology','Information Technology','Law','Law','Nursing, Midwifery & Health','Nursing, Midwifery & Health','Science')),'Science')),
SQL Actions ExamplesSQL Actions Examples
• On Delete CascadeOn Delete Cascade
CONSTRAINT Zaharia_UTS_CourseUACCode_CourseIDFK FOREIGN CONSTRAINT Zaharia_UTS_CourseUACCode_CourseIDFK FOREIGN KEY (CourseID) REFERENCES Zaharia_UTS_CourseKEY (CourseID) REFERENCES Zaharia_UTS_Course
ON DELETE CASCADEON DELETE CASCADE
ON UPDATE CASCADEON UPDATE CASCADE
SQL Actions ExamplesSQL Actions Examples For example if we would delete a Course from For example if we would delete a Course from
the Course table:the Course table:
DELETE FROM Zaharia_UTS_Course WHERE CourseID = 'C10026';DELETE FROM Zaharia_UTS_Course WHERE CourseID = 'C10026';
This would also delete the Course’s UAC This would also delete the Course’s UAC code details from the CourseUACCode code details from the CourseUACCode table, and we can see this after:table, and we can see this after:SELECT * FROM Zaharia_UTS_CourseUACCode;SELECT * FROM Zaharia_UTS_CourseUACCode;
UACNumber UACNumber CourseID CourseID UACTypeUACType
605002605002 C10219C10219 CSPCSP
615002 615002 C10219 C10219 DFEEDFEE
942600942600 C01457C01457 Autumn semesterAutumn semester
945600 945600 C01457C01457 Spring semesterSpring semester
No C10026 !
SQL Actions Examples (2)SQL Actions Examples (2)
• On Delete RestrictOn Delete Restrict
CONSTRAINT Zaharia_UTS_Subject_SubjectEFTSLFK FOREIGN KEY CONSTRAINT Zaharia_UTS_Subject_SubjectEFTSLFK FOREIGN KEY (SubjectEFTSL) REFERENCES Zaharia_UTS_SubjectFee(SubjectEFTSL) REFERENCES Zaharia_UTS_SubjectFee
ON DELETE RESTRICTON DELETE RESTRICT ON UPDATE CASCADEON UPDATE CASCADE
SQL Actions Examples (2)SQL Actions Examples (2)
For example if we try to delete a subject’s For example if we try to delete a subject’s EFTSL from the SubjectFee table:EFTSL from the SubjectFee table:DELETE FROM Zaharia_UTS_SubjectFee WHERE SubjectEFTSL = 0.125;DELETE FROM Zaharia_UTS_SubjectFee WHERE SubjectEFTSL = 0.125;
We get the error: We get the error: update or delete on "zaharia_uts_subjectfee" violates foreign key constraint update or delete on "zaharia_uts_subjectfee" violates foreign key constraint "zaharia_uts_subject_subjecteftslfk" on "zaharia_uts_subject“"zaharia_uts_subject_subjecteftslfk" on "zaharia_uts_subject“
Since the foreign key SubjectEFTSL in the Since the foreign key SubjectEFTSL in the Subject table is restricted from deleting data in Subject table is restricted from deleting data in the Subject table that shares the value the Subject table that shares the value
SubjectEFTSL = 0.125SubjectEFTSL = 0.125
Creating a View ExampleCreating a View Example
CREATE VIEW Zaharia_UTS_CoursePriceCREATE VIEW Zaharia_UTS_CoursePrice
(CourseID, CourseName, CourseCP, (CourseID, CourseName, CourseCP, CoursePriceCom, CoursePriceDom)CoursePriceCom, CoursePriceDom)
AS SELECT CourseID, CourseName, AS SELECT CourseID, CourseName, LoadCP, CourseEFTSL * 7118, LoadCP, CourseEFTSL * 7118, CourseEFTSL * 18240CourseEFTSL * 18240
FROM Zaharia_UTS_Course;FROM Zaharia_UTS_Course;
Creating a View ExampleCreating a View Example
Query view as if a table:Query view as if a table:
Show the subject prices for the subject Database Show the subject prices for the subject Database Fundamentals in the BBus BScIT courseFundamentals in the BBus BScIT course
SELECT SubjectID, ((CoursePriceCom / CourseCP) * CP) AS SubjectComPrice, SELECT SubjectID, ((CoursePriceCom / CourseCP) * CP) AS SubjectComPrice, ((CoursePriceDom / CourseCP) * CP) AS SubjectDomPrice((CoursePriceDom / CourseCP) * CP) AS SubjectDomPrice
FROM Zaharia_UTS_Subject, Zaharia_UTS_CoursePriceFROM Zaharia_UTS_Subject, Zaharia_UTS_CoursePrice
WHERE SubjectName = 'Database Fundamentals'WHERE SubjectName = 'Database Fundamentals'
AND CourseName = 'Bachelor of Business Bachelor of Science in Information AND CourseName = 'Bachelor of Business Bachelor of Science in Information Technology';Technology';
SubjectIDSubjectID SubjectComPrice SubjectComPrice SubjectDomPriceSubjectDomPrice
3127131271 889.75889.75 2280 2280
ENDEND