Presentation is loading. Please wait.

Presentation is loading. Please wait.

UTS DATABASE Chris Zaharia.

Similar presentations


Presentation on theme: "UTS DATABASE Chris Zaharia."— Presentation transcript:

1 UTS DATABASE Chris Zaharia

2 The Domain – UTS

3 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 i.e. A course can have core, major etc structures that have a number of subjects in each structure category

4 Entity Relationship Diagram
Course Course CourseID CourseName CourseDesc CourseGrad CourseAward CourseAward2 CRICOSCode CommSupport LoadCP CourseEFTSL FacResp FacColl Location Subject Subject SubjectID SubjectName SubjectDesc SubjectGrad CP Faculty SubjectEFTSL * CourseUACCode CourseUACCode UACNumber CourseID * UACType SubjectRequisite SubjectID * ReqSubject * SubjectRequisite SubjectStructureChoice SubjectID * StructureChoiceID * SubjectStructureChoice CourseStructureChoice CourseStructureChoice StructureID * StructureChoiceID * SubjectChoice StructureChoice StructureChoiceID StructureChoiceName CourseStructure CourseStructure CourseID * StructureID * StructureCP Structure Structure StructuretID StructureType SubjectFee SubjectFee SubjectEFTSL FeeComPrice FeeDomPrice SubjectStructure SubjectStructure SubjectID * StructureID *

5 One-to-many Relationship
SubjectID SubjectName Subject EFTSL 22107 Accounting for Business 0.125 31257 Information System Development Methodologies 31271 Database Fundamentals 70113 Legal Process and History 0.208 SubjectEFTSL FeeComPrice FeeDomPrice 0.083 694.42 1648 0.125 889.75 2280 0.208 4120 0.25 1779.5 4920 Table 1 - SubjectFee Table 1 - Subject Primary Key Primary Key Foreign Key Both tables have a one-to-many relationship Linked by a foreign key

6 One-to-many Relationship
ERD Subject SubjectID SubjectName SubjectDesc SubjectGrad CP Faculty SubjectEFTSL * SubjectFee SubjectEFTSL FeeComPrice FeeDomPrice Has

7 Many-to-many Relationship
Primary Key SubjectID SubjectName 31270 Networking Essentials 31271 Database Fundamentals 31280 Strategic IT Project StructureID StructureType CBK90781 Major CBK90782 Major/Two Submajors/Electives STM90651 Core Foreign Key Table 1 - Subject Table 2 - Structure Table 3 - SubjectStructure Primary Key SubjectID StructureID 31270 STM90651 31271 31280 CBK90781 CBK90782 Foreign Key Both one-to-many paired Relationships (T1,T3; T2,T3) Creates a many-to-many relationship Table 1 and Table 2 Primary keys are foreign Keys in table 3 Primary Key

8 Many-to-many Relationship
ERD Subject SubjectID SubjectName SubjectDesc SubjectGrad CP Faculty SubjectEFTSL * Structure StructuretID StructureType SubjectStructure SubjectID * StructureID * Part of Contains

9 Queries 1. Show all undergraduate courses.
SELECT courseID, courseName, courseGrad FROM Zaharia_UTS_Course WHERE courseGrad = 'Undergraduate'; CourseID CourseName CourseGrad C10026 Bachelor of Business Undergraduate C10148 Bachelor of Science in Information Technology C10219 Bachelor of Business Bachelor of Science in Information Technology

10 Queries 2. Show all subjects with requisites and display their requisites. SELECT subjectID, subjectName, reqSubject FROM Zaharia_UTS_Subject NATURAL JOIN Zaharia_UTS_SubjectRequisite; SubjectID SubjectName ReqSubject 22320 Accounting for Business Combinations 22107 31257 Information System Development Methodologies 31270 31269 Business Requirements Modelling 31266 31272 Project Management and the Professional 31280 Strategic IT Project 31276

11 Queries 3. Show subjects along with their structure types.
SELECT SubjectID, Zaharia_UTS_Structure.StructureID, StructureType FROM Zaharia_UTS_Structure, Zaharia_UTS_SubjectStructure WHERE Zaharia_UTS_Structure.StructureID = Zaharia_UTS_SubjectStructure.StructureID;

12 Queries SubjectID StructureID StructureType 22107 STM90273 Core 22320
CBK90169 Major CBK90170 Major/Two Submajors/Submajor + Four Electives 31257 CBK90781 CBK90782 Major/Two Submajors/Electives 31266 STM90651 31269 31270 31271 31272 31276 31280 70113

13 Queries 4. Show the average of the Commonwealth and Domestic fee price for each subject whose fee average is over $5000 SELECT subjectID, avg(FeeComPrice + FeeDomPrice) AS Average_SubjectPrice FROM Zaharia_UTS_SubjectFee NATURAL JOIN Zaharia_UTS_Subject GROUP BY subjectID HAVING avg(FeeComPrice + FeeDomPrice) > 5000; SubjectID Average_SubjectPrice 70113

14 Queries 5. Show all core subjects that are newer then the very first core subject. SELECT subjectID FROM Zaharia_UTS_SubjectStructure NATURAL JOIN Zaharia_UTS_Structure WHERE structureType = 'Core' AND subjectID > ( SELECT min(subjectID) FROM Zaharia_UTS_SubjectStructure ); SubjectID 31266 31269 31270 31271 31272 SELECT subjectID FROM Zaharia_UTS_SubjectStructure NATURAL JOIN Zaharia_UTS_Structure WHERE structureType = 'Core' and subjectID > ( SELECT min(subjectID) FROM Zaharia_UTS_SubjectStructure );

15 Queries 6. Show all courses that share the same graduation status as course C10219 (BBus BScIT). SELECT c1.courseID FROM Zaharia_UTS_Course c1, Zaharia_UTS_Course C2 WHERE c1.courseGrad = c2.courseGrad AND c2.courseID = 'C10219' AND c1.courseID <> 'C10219'; CourseID C10026 C10148

16 CHECK Constraint Examples
Check for graduation status CONSTRAINT Zaharia_UTS_Course_CourseGrad CHECK (CourseGrad IN ( 'Undergraduate', 'Postgraduate')), Check value of Course EFTSL CONSTRAINT Zaharia_UTS_Course_CourseEFTSL CHECK (CourseEFTSL BETWEEN 0.5 AND 7)

17 CHECK Constraint Examples
Check for Faculty Responsible CONSTRAINT Zaharia_UTS_Course_FacResp CHECK (FacResp IN ( 'Business', 'Design, Architecture and Building', 'Education', 'Engineering', 'Humanities', 'Information Technology', 'Law', 'Nursing, Midwifery & Health', 'Science')),

18 SQL Actions Examples On Delete Cascade
CONSTRAINT Zaharia_UTS_CourseUACCode_CourseIDFK FOREIGN KEY (CourseID) REFERENCES Zaharia_UTS_Course ON DELETE CASCADE ON UPDATE CASCADE

19 SQL Actions Examples For example if we would delete a Course from the Course table: DELETE FROM Zaharia_UTS_Course WHERE CourseID = 'C10026'; This would also delete the Course’s UAC code details from the CourseUACCode table, and we can see this after: SELECT * FROM Zaharia_UTS_CourseUACCode; No C10026 ! UACNumber CourseID UACType 605002 C10219 CSP 615002 DFEE 942600 C01457 Autumn semester 945600 Spring semester

20 SQL Actions Examples (2)
On Delete Restrict CONSTRAINT Zaharia_UTS_Subject_SubjectEFTSLFK FOREIGN KEY (SubjectEFTSL) REFERENCES Zaharia_UTS_SubjectFee ON DELETE RESTRICT ON UPDATE CASCADE

21 SQL Actions Examples (2)
For example if we try to delete a subject’s EFTSL from the SubjectFee table: DELETE FROM Zaharia_UTS_SubjectFee WHERE SubjectEFTSL = 0.125; We get the error: update or delete on "zaharia_uts_subjectfee" violates foreign key constraint "zaharia_uts_subject_subjecteftslfk" on "zaharia_uts_subject“ Since the foreign key SubjectEFTSL in the Subject table is restricted from deleting data in the Subject table that shares the value SubjectEFTSL = 0.125

22 Creating a View Example
CREATE VIEW Zaharia_UTS_CoursePrice (CourseID, CourseName, CourseCP, CoursePriceCom, CoursePriceDom) AS SELECT CourseID, CourseName, LoadCP, CourseEFTSL * 7118, CourseEFTSL * 18240 FROM Zaharia_UTS_Course;

23 Creating a View Example
Query view as if a table: Show the subject prices for the subject Database Fundamentals in the BBus BScIT course SELECT SubjectID, ((CoursePriceCom / CourseCP) * CP) AS SubjectComPrice, ((CoursePriceDom / CourseCP) * CP) AS SubjectDomPrice FROM Zaharia_UTS_Subject, Zaharia_UTS_CoursePrice WHERE SubjectName = 'Database Fundamentals' AND CourseName = 'Bachelor of Business Bachelor of Science in Information Technology'; SubjectID SubjectComPrice SubjectDomPrice 31271 889.75 2280

24 END


Download ppt "UTS DATABASE Chris Zaharia."

Similar presentations


Ads by Google