Class Scheduling System Table Structure

In Class Scheduling System/ Module you have to consider the following constraint: 1. Academic Year and Term 2. Class Section 3. Class Room and Building 4. Faculty 5. Subjects 6. Curriculum 7. Class Schedule (Subject Offering) - Class Schedule is set for maximum of 5 Schedule per Subject USING MySQL as the Primary Database......
  1. CREATE TABLE `tblayterm` (
  2.   `TermID` INT(10) UNSIGNED NOT NULL,
  3.   `SchoolYear` VARCHAR(10) DEFAULT NULL,
  4.   `Locked` tinyint(1) DEFAULT '0',
  5.   `SchoolTerm` VARCHAR(45) DEFAULT NULL,
  6.   `StartofSY` datetime DEFAULT NULL,
  7.   `EndofSY` datetime DEFAULT NULL,
  8.   `ExpireReg` tinyint(3) UNSIGNED DEFAULT NULL,
  9.   `ExpireDays` INT(10) UNSIGNED DEFAULT NULL,
  10.   `LastModified` VARCHAR(45) DEFAULT NULL,
  11.   `LastModifiedDate` datetime DEFAULT NULL,
  12.   `NumWeeks` INT(11) DEFAULT NULL,
  13.   `Hidden` INT(11) DEFAULT NULL,
  14.   PRIMARY KEY (`TermID`) USING BTREE
  15. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  16.  
  17. CREATE TABLE `tblsection` (
  18.   `SectionID` VARCHAR(20) NOT NULL,
  19.   `SectionTitle` VARCHAR(255) DEFAULT NULL,
  20.   `YearLevelID` INT(11) DEFAULT '0',
  21.   `TermID` INT(10) UNSIGNED DEFAULT NULL,
  22.   `CampusID` VARCHAR(45) DEFAULT NULL,
  23.   `CollegeID` VARCHAR(45) DEFAULT NULL,
  24.   `CurriculumID` VARCHAR(45) DEFAULT NULL,
  25.   `ProgramID` VARCHAR(45) DEFAULT NULL,
  26.   `AdviserID` VARCHAR(45) DEFAULT NULL,
  27.   `IsBlock` tinyint(3) UNSIGNED DEFAULT NULL,
  28.   `RoomID` VARCHAR(45) DEFAULT NULL,
  29.   `Limit` INT(10) UNSIGNED DEFAULT NULL,
  30.   `IsEvening` tinyint(3) UNSIGNED DEFAULT NULL,
  31.   `IsDissolved` tinyint(3) UNSIGNED DEFAULT NULL,
  32.   `CreationDate` datetime DEFAULT NULL,
  33.   `CreatedBy` VARCHAR(45) DEFAULT NULL,
  34.   `ModifiedBy` VARCHAR(45) DEFAULT NULL,
  35.   `ModifiedOn` datetime DEFAULT NULL,
  36.   PRIMARY KEY (`SectionID`),
  37.   KEY `YearLevelID` (`YearLevelID`),
  38.   KEY `TermID` (`TermID`) USING BTREE,
  39.   KEY `CampusID` (`CampusID`) USING BTREE,
  40.   KEY `CollegeID` (`CollegeID`) USING BTREE,
  41.   KEY `ProgramID` (`ProgramID`) USING BTREE,
  42.   CONSTRAINT `FKTermID` FOREIGN KEY (`TermID`) REFERENCES `tblayterm` (`TermID`) ON DELETE CASCADE ON UPDATE CASCADE
  43. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  44.  
  45. CREATE TABLE `tblbuilding` (
  46.   `BldgID` INT(11) NOT NULL,
  47.   `CampusID` INT(11) DEFAULT NULL,
  48.   `BldgName` VARCHAR(100) CHARACTER SET latin1 DEFAULT NULL,
  49.   `BldgOtherName` VARCHAR(100) CHARACTER SET latin1 DEFAULT NULL,
  50.   `Acronym` VARCHAR(45) CHARACTER SET latin1 DEFAULT NULL,
  51.   `FloorsCount` INT(11) DEFAULT NULL,
  52.   `BldgPic` longblob,
  53.   `IsLANReady` tinyint(3) UNSIGNED DEFAULT NULL,
  54.   `Elevator` tinyint(3) UNSIGNED DEFAULT NULL,
  55.   `Escalator` tinyint(3) UNSIGNED DEFAULT NULL,
  56.   PRIMARY KEY (`BldgID`),
  57.   KEY `Index_2` (`CampusID`),
  58.   CONSTRAINT `FK_CampusID` FOREIGN KEY (`CampusID`) REFERENCES `tblcampus` (`CampusID`) ON DELETE CASCADE ON UPDATE CASCADE
  59. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  60.  
  61. CREATE TABLE `tblroom` (
  62.   `RoomID` VARCHAR(20) NOT NULL,
  63.   `BldgID` INT(11) DEFAULT NULL,
  64.   `Floor` INT(11) DEFAULT NULL,
  65.   `Room` VARCHAR(100) DEFAULT NULL,
  66.   `Capacity` INT(11) DEFAULT NULL,
  67.   `RoomNo` VARCHAR(20) DEFAULT NULL,
  68.   `RoomTypeID` INT(11) DEFAULT NULL,
  69.   `IsAirConditioned` tinyint(3) UNSIGNED DEFAULT NULL,
  70.   `IsUsable` tinyint(3) UNSIGNED DEFAULT NULL,
  71.   `IsLANMember` tinyint(3) UNSIGNED DEFAULT NULL,
  72.   `AllowNightClass` tinyint(3) UNSIGNED DEFAULT NULL,
  73.   `Shared` tinyint(3) UNSIGNED DEFAULT NULL,
  74.   PRIMARY KEY (`RoomID`),
  75.   KEY `RoomTypeID` (`RoomTypeID`),
  76.   CONSTRAINT `FK_RoomTypeID` FOREIGN KEY (`RoomTypeID`) REFERENCES `tblroomtypes` (`RoomTypeID`) ON DELETE CASCADE ON UPDATE CASCADE
  77. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  78.  
  79. CREATE TABLE `tblteacher` (
  80.   `TeacherID` VARCHAR(10) NOT NULL,
  81.   `EmployeeID` VARCHAR(45) NOT NULL,
  82.   `DeptID` VARCHAR(45) NOT NULL,
  83.   `CampusID` VARCHAR(45) NOT NULL,
  84.   `CollegeID` VARCHAR(45) NOT NULL,
  85.   `RankID` VARCHAR(45) NOT NULL,
  86.   `IsRegularFaculty` tinyint(3) UNSIGNED NOT NULL DEFAULT '1',
  87.   `IsFullTime` tinyint(3) UNSIGNED NOT NULL,
  88.   `PRC_LicenseID` VARCHAR(45) NOT NULL,
  89.   `DegreeDiscipline` VARCHAR(45) NOT NULL,
  90.   `TeachLoadLevel` INT(10) UNSIGNED NOT NULL,
  91.   PRIMARY KEY (`TeacherID`),
  92.   KEY `TeacherID` (`TeacherID`)
  93. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  94.  
  95. CREATE TABLE `tblcurriculum` (
  96.   `CurriculumID` VARCHAR(45) NOT NULL,
  97.   `CurriculumCode` VARCHAR(45) NOT NULL,
  98.   `Description` VARCHAR(200) DEFAULT NULL,
  99.   `Notes` text,
  100.   `CreatedBy` VARCHAR(45) DEFAULT NULL,
  101.   `CreationDate` datetime DEFAULT NULL,
  102.   `ModifiedBy` VARCHAR(45) DEFAULT NULL,
  103.   `ModifiedDate` datetime DEFAULT NULL,
  104.   `IsLocked` tinyint(3) UNSIGNED DEFAULT '0',
  105.   `DateLocked` datetime DEFAULT NULL,
  106.   `ProgramID` VARCHAR(45) DEFAULT NULL,
  107.   `MajorID` VARCHAR(45) DEFAULT NULL,
  108.   `CampusID` INT(11) DEFAULT NULL,
  109.   PRIMARY KEY (`CurriculumID`),
  110.   KEY `Index_3` (`ProgramID`) USING BTREE,
  111.   KEY `Index_1` (`CampusID`) USING BTREE,
  112.   KEY `Index_2` (`MajorID`) USING BTREE,
  113.   CONSTRAINT `FKCampusID` FOREIGN KEY (`CampusID`) REFERENCES `tblcampus` (`CampusID`) ON DELETE CASCADE ON UPDATE CASCADE,
  114.   CONSTRAINT `FKProgramID` FOREIGN KEY (`ProgramID`) REFERENCES `tblprograms` (`ProgID`) ON DELETE CASCADE ON UPDATE CASCADE
  115. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  116.  
  117. CREATE TABLE `tblcurriculumdetails` (
  118.   `IndexID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  119.   `CurriculumID` VARCHAR(45) NOT NULL,
  120.   `YearTermID` INT(10) UNSIGNED NOT NULL,
  121.   `SubjectID` VARCHAR(45) NOT NULL,
  122.   `YearStandingID` INT(10) UNSIGNED DEFAULT NULL,
  123.   `EquivalentSubjectID` VARCHAR(45) CHARACTER SET latin1 NOT NULL,
  124.   PRIMARY KEY (`IndexID`) USING BTREE,
  125.   KEY `CurriculumID` (`CurriculumID`) USING BTREE,
  126.   KEY `SubjectID` (`SubjectID`) USING BTREE,
  127.   KEY `YearTermID` (`YearTermID`) USING BTREE,
  128.   CONSTRAINT `FK_CurriculumID` FOREIGN KEY (`CurriculumID`) REFERENCES `tblcurriculum` (`CurriculumID`) ON DELETE CASCADE ON UPDATE CASCADE,
  129.   CONSTRAINT `FK_YearTermID` FOREIGN KEY (`YearTermID`) REFERENCES `tblyearlevelterm` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
  130. ) ENGINE=InnoDB AUTO_INCREMENT=184 DEFAULT CHARSET=utf8;
  131.  
  132. CREATE TABLE `tblsection` (
  133.   `SectionID` VARCHAR(20) NOT NULL,
  134.   `SectionTitle` VARCHAR(255) DEFAULT NULL,
  135.   `YearLevelID` INT(11) DEFAULT '0',
  136.   `TermID` INT(10) UNSIGNED DEFAULT NULL,
  137.   `CampusID` VARCHAR(45) DEFAULT NULL,
  138.   `CollegeID` VARCHAR(45) DEFAULT NULL,
  139.   `CurriculumID` VARCHAR(45) DEFAULT NULL,
  140.   `ProgramID` VARCHAR(45) DEFAULT NULL,
  141.   `AdviserID` VARCHAR(45) DEFAULT NULL,
  142.   `IsBlock` tinyint(3) UNSIGNED DEFAULT NULL,
  143.   `RoomID` VARCHAR(45) DEFAULT NULL,
  144.   `Limit` INT(10) UNSIGNED DEFAULT NULL,
  145.   `IsEvening` tinyint(3) UNSIGNED DEFAULT NULL,
  146.   `IsDissolved` tinyint(3) UNSIGNED DEFAULT NULL,
  147.   `CreationDate` datetime DEFAULT NULL,
  148.   `CreatedBy` VARCHAR(45) DEFAULT NULL,
  149.   `ModifiedBy` VARCHAR(45) DEFAULT NULL,
  150.   `ModifiedOn` datetime DEFAULT NULL,
  151.   PRIMARY KEY (`SectionID`),
  152.   KEY `YearLevelID` (`YearLevelID`),
  153.   KEY `TermID` (`TermID`) USING BTREE,
  154.   KEY `CampusID` (`CampusID`) USING BTREE,
  155.   KEY `CollegeID` (`CollegeID`) USING BTREE,
  156.   KEY `ProgramID` (`ProgramID`) USING BTREE,
  157.   CONSTRAINT `FKTermID` FOREIGN KEY (`TermID`) REFERENCES `tblayterm` (`TermID`) ON DELETE CASCADE ON UPDATE CASCADE
  158. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  159.  
  160. CREATE TABLE `tblclassschedule` (
  161.   `SubjectOfferingID` VARCHAR(31) NOT NULL,
  162.   `TermID` INT(20) NOT NULL,
  163.   `SubjectID` VARCHAR(10) DEFAULT NULL,
  164.   `SectionID` VARCHAR(20) DEFAULT NULL,
  165.   `IsSpecialClasses` tinyint(1) DEFAULT NULL,
  166.   `SchedTimeStart` INT(10) UNSIGNED DEFAULT NULL,
  167.   `SchedTimeEnd` INT(10) UNSIGNED DEFAULT NULL,
  168.   `TeacherID` VARCHAR(10) DEFAULT NULL,
  169.   `RoomID` VARCHAR(50) DEFAULT NULL,
  170.   `Days` VARCHAR(20) DEFAULT NULL,
  171.   `EventID1` INT(10) UNSIGNED DEFAULT NULL,
  172.   `Sched1` VARCHAR(45) DEFAULT NULL,
  173.   `SchedTimeStart2` INT(10) UNSIGNED DEFAULT NULL,
  174.   `SchedTimeEnd2` INT(10) UNSIGNED DEFAULT NULL,
  175.   `TeacherID2` VARCHAR(45) DEFAULT NULL,
  176.   `RoomID2` VARCHAR(45) DEFAULT NULL,
  177.   `Days2` VARCHAR(45) DEFAULT NULL,
  178.   `EventID2` INT(10) UNSIGNED DEFAULT NULL,
  179.   `Sched2` VARCHAR(45) DEFAULT NULL,
  180.   `SchedTimeStart3` INT(10) UNSIGNED DEFAULT NULL,
  181.   `SchedTimeEnd3` INT(10) UNSIGNED DEFAULT NULL,
  182.   `TeacherID3` VARCHAR(45) DEFAULT NULL,
  183.   `RoomID3` VARCHAR(45) DEFAULT NULL,
  184.   `Days3` VARCHAR(45) DEFAULT NULL,
  185.   `EventID3` INT(10) UNSIGNED DEFAULT NULL,
  186.   `Sched3` VARCHAR(45) DEFAULT NULL,
  187.   `SchedTimeStart4` INT(10) UNSIGNED DEFAULT NULL,
  188.   `SchedTimeEnd4` INT(10) UNSIGNED DEFAULT NULL,
  189.   `TeacherID4` VARCHAR(45) DEFAULT NULL,
  190.   `RoomID4` VARCHAR(45) DEFAULT NULL,
  191.   `Days4` VARCHAR(45) DEFAULT NULL,
  192.   `EventID4` INT(10) UNSIGNED DEFAULT NULL,
  193.   `Sched4` VARCHAR(45) DEFAULT NULL,
  194.   `SchedTimeStart5` INT(10) UNSIGNED DEFAULT NULL,
  195.   `SchedTimeEnd5` INT(10) UNSIGNED DEFAULT NULL,
  196.   `TeacherID5` VARCHAR(45) DEFAULT NULL,
  197.   `RoomID5` VARCHAR(45) DEFAULT NULL,
  198.   `Days5` VARCHAR(45) DEFAULT NULL,
  199.   `EventID5` INT(10) UNSIGNED DEFAULT NULL,
  200.   `Sched5` VARCHAR(45) DEFAULT NULL,
  201.   `OverRideConflict` tinyint(4) DEFAULT NULL,
  202.   `IsDissolved` tinyint(4) DEFAULT NULL,
  203.   `PostedBy` VARCHAR(45) DEFAULT NULL,
  204.   `DatePosted` VARCHAR(45) DEFAULT NULL,
  205.   `RoomPostedBy` VARCHAR(45) DEFAULT NULL,
  206.   `RoomDatePosted` VARCHAR(20) DEFAULT NULL,
  207.   `FacultyDatePosted` VARCHAR(45) DEFAULT NULL,
  208.   `FacultyPostedBy` VARCHAR(45) DEFAULT NULL,
  209.   `CreationDate` VARCHAR(20) DEFAULT NULL,
  210.   `CreatedBy` VARCHAR(70) DEFAULT NULL,
  211.   `ModifiedDate` VARCHAR(45) DEFAULT NULL,
  212.   `ModifiedBy` VARCHAR(70) DEFAULT NULL,
  213.   PRIMARY KEY (`SubjectOfferingID`),
  214.   KEY `SubjectID` (`SubjectID`),
  215.   KEY `SectionID` (`SectionID`) USING BTREE,
  216.   KEY `TermID` (`TermID`) USING BTREE,
  217.   CONSTRAINT `FKSectionID` FOREIGN KEY (`SectionID`) REFERENCES `tblsection` (`SectionID`) ON DELETE CASCADE ON UPDATE CASCADE,
  218.   CONSTRAINT `FK_SubjectID` FOREIGN KEY (`SubjectID`) REFERENCES `tblsubject` (`SubjectID`) ON DELETE CASCADE ON UPDATE CASCADE
  219. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
==================STORED PROCEDURE ==============================
  1. CREATE DEFINER = 'root'@'localhost' PROCEDURE `GetClassScheduleConflicts`(
  2.         IN TermID INTEGER,
  3.         IN SectionID VARCHAR(45),
  4.         IN sDay VARCHAR(10),
  5.         IN TimeStart VARCHAR(10),
  6.         IN TimeEnd VARCHAR(10)
  7.     )
  8.     NOT DETERMINISTIC
  9.     CONTAINS SQL
  10.     SQL SECURITY DEFINER
  11.     COMMENT ''
  12.  
  13. BEGIN
  14.         SELECT  CS.SubjectOfferingID, CS.TermID, CS.SubjectID, S.SubjectCode, S.SubjectTitle, S.CreditUnits,
  15.                 CS.SectionID, CSec.SectionName,
  16.                 CS.Sched1, fnRoomName2(RoomID) AS Room_1,
  17.                 CS.Sched2, fnRoomName2(RoomID2) AS Room_2,
  18.                 CS.Sched3, fnRoomName2(RoomID3) AS Room_3,
  19.                 CS.Sched4, fnRoomName2(RoomID4) AS Room_4,
  20.                 CS.Sched5, fnRoomName2(RoomID4) AS Room_5,
  21.                 CS.Days1,CS.Days2,CS.Days3,CS.Days4,CS.Days5,
  22.                 fnCollegeCode(CSec.CollegeID) AS CollegeCode,
  23.                 fnProgramCode(CSec.ProgramID) AS ProgramCode
  24.         FROM   tblClassSchedule AS CS LEFT JOIN
  25.                 tblSubject AS S ON S.SubjectID = CS.SubjectID LEFT JOIN
  26.                 tblSection AS CSec ON CSec.SectionID = CS.SectionID    
  27.         WHERE (CS.TermID = TermID) AND (CS.SectionID = SectionID)
  28.             AND (
  29.                 ( (CS.Days1 LIKE sDay) AND ((CS.SchedTimeStart BETWEEN TimeStart AND TimeEnd) OR (CS.SchedTimeEnd BETWEEN TimeStart AND TimeEnd) OR ((CS.SchedTimeEnd > TimeStart AND CS.SchedTimeEnd
  30.                     AND ((CS.SchedTimeEnd > TimeStart AND CS.SchedTimeEnd
  31.                 )
  32.             OR
  33.                 ( (CS.Days2 LIKE sDay) AND ((CS.SchedTimeStart2 BETWEEN TimeStart AND TimeEnd) OR (CS.SchedTimeEnd2 BETWEEN TimeStart AND TimeEnd) OR ((CS.Time2_End > TimeStart AND CS.SchedTimeEnd2
  34.                     AND ((CS.SchedTimeEnd2 > TimeStart AND CS.Time2_End
  35.                 )
  36.             OR
  37.                 ( (CS.Days3 LIKE sDay) AND ((CS.SchedTimeStart3 BETWEEN TimeStart AND TimeEnd) OR (CS.SchedTimeEnd3 BETWEEN TimeStart AND TimeEnd) OR ((CS.Time3_End > TimeStart AND CS.SchedTimeEnd3
  38.                     AND ((CS.SchedTimeEnd3 > TimeStart AND CS.SchedTimeEnd3
  39.                 )
  40.             OR
  41.                 ( (CS.Days4 LIKE sDay) AND ((CS.SchedTimeStart4 BETWEEN TimeStart AND TimeEnd) OR (CS.SchedTimeEnd4 BETWEEN TimeStart AND TimeEnd) OR ((CS.Time4_End > TimeStart AND CS.SchedTimeEnd4
  42.                     AND ((CS.SchedTimeEnd4 > TimeStart AND CS.SchedTimeEnd4
  43.                 )
  44.             OR
  45.                 ( (CS.Days5 LIKE sDay) AND ((CS.SchedTimeStart5 BETWEEN TimeStart AND TimeEnd) OR (CS.SchedTimeEnd5 BETWEEN TimeStart AND TimeEnd) OR ((CS.Time5_End > @TimeStart AND CS.SchedTimeEnd5
  46.                     AND ((CS.SchedTimeEnd5 > TimeStart AND CS.SchedTimeEnd5
  47.                 )
  48.                 );
  49. END;
  50.  
  51. CREATE DEFINER = 'root'@'localhost' PROCEDURE `GetFacultyScheduleConflicts`(
  52.         TermID  INT,
  53.         FacultyID  VARCHAR(15),
  54.         sDay  VARCHAR(10),
  55.         TimeStart VARCHAR(10),
  56.         TimeEnd VARCHAR(10)
  57.     )
  58.     NOT DETERMINISTIC
  59.     CONTAINS SQL
  60.     SQL SECURITY DEFINER
  61.     COMMENT ''
  62.  
  63. BEGIN
  64.     SELECT  SubjectOfferingID, CS.TermID, CS.SubjectID, S.SubjectCode, S.SubjectTitle, S.CreditUnits, CSec.SectionTitle,
  65.             CS.Sched1, fnRoomName2(CS.RoomID) AS Room_1,
  66.             CS.Sched2, fnRoomName2(CS.RoomID2) AS Room_2,
  67.             CS.Sched3, fnRoomName2(CS.RoomID3) AS Room_3,
  68.             CS.Sched4, fnRoomName2(CS.RoomID4) AS Room_4,
  69.             CS.Sched5, fnRoomName2(CS.RoomID5) AS Room_5,
  70.             fnProgramCode(CSec.ProgramID) AS ProgramCode
  71.     FROM tblClassSchedule AS CS LEFT JOIN
  72.             tblSubject AS S ON S.SubjectID = CS.SubjectID LEFT JOIN
  73.             tblSection AS CSec ON CSec.SectionID = CS.SectionID
  74.     WHERE   (CS.TermID = TermID) AND
  75.             (CS.TeacherID = FacultyID) AND
  76.             (CS.Days LIKE sDay) AND
  77.             ((SchedTimeStart BETWEEN TimeStart AND TimeEnd) OR (SchedTimeEnd BETWEEN TimeStart AND TimeEnd)
  78.             OR ((SchedTimeEnd > TimeStart AND SchedTimeEnd
  79.             AND ((SchedTimeEnd > TimeStart AND SchedTimeEnd
  80.  
  81.         /*----------------------------------*/    
  82.     UNION -- SCHEDULE.1 TO SCHEDULE.2
  83.     /*----------------------------------*/
  84.  
  85.     SELECT  SubjectOfferingID, CS.TermID, CS.SubjectID, S.SubjectCode, S.SubjectTitle, S.CreditUnits, CSec.SectionTitle,
  86.             CS.Sched1, fnRoomName2(CS.RoomID) AS Room_1,
  87.             CS.Sched2, fnRoomName2(CS.RoomID2) AS Room_2,
  88.             CS.Sched3, fnRoomName2(CS.RoomID3) AS Room_3,
  89.             CS.Sched4, fnRoomName2(CS.RoomID4) AS Room_4,
  90.             CS.Sched5, fnRoomName2(CS.RoomID5) AS Room_5,
  91.             fnProgramCode(CSec.ProgramID) AS ProgramCode
  92.     FROM    tblClassSchedule AS CS LEFT JOIN
  93.             tblSubject AS S ON S.SubjectID = CS.SubjectID LEFT JOIN
  94.             tblSection AS CSec ON CSec.SectionID = CS.SectionID
  95.     WHERE   (CS.TermID = TermID) AND
  96.             (CS.TeacherID2 = FacultyID) AND
  97.             (Days2 LIKE sDay) AND
  98.             ((SchedTimeStart2 BETWEEN TimeStart AND TimeEnd) OR (SchedTimeEnd2 BETWEEN TimeStart AND TimeEnd)
  99.             OR ((SchedTimeEnd2 > TimeStart AND SchedTimeEnd2
  100.             AND ((SchedTimeEnd2 > TimeStart AND SchedTimeEnd2
  101.  
  102.         /*----------------------------------*/      
  103.     UNION -- SCHEDULE.2 TO SCHEDULE.3
  104.         /*----------------------------------*/
  105.  
  106.     SELECT  SubjectOfferingID, CS.TermID, CS.SubjectID, S.SubjectCode, S.SubjectTitle, S.CreditUnits, CSec.SectionTitle,
  107.             CS.Sched1, fnRoomName2(CS.RoomID) AS Room_1,
  108.             CS.Sched2, fnRoomName2(CS.RoomID2) AS Room_2,
  109.             CS.Sched3, fnRoomName2(CS.RoomID3) AS Room_3,
  110.             CS.Sched4, fnRoomName2(CS.RoomID4) AS Room_4,
  111.             CS.Sched5, fnRoomName2(CS.RoomID5) AS Room_5,
  112.             fnProgramCode(CSec.ProgramID) AS ProgramCode
  113.     FROM    tblClassSchedule AS CS LEFT JOIN
  114.             tblSubject AS S ON S.SubjectID = CS.SubjectID LEFT JOIN
  115.             tblSection AS CSec ON CSec.SectionID = CS.SectionID
  116.     WHERE   (CS.TermID = TermID) AND
  117.             (CS.TeacherID3 = FacultyID) AND
  118.             (Days3 LIKE sDay) AND
  119.             ((SchedTimeStart3 BETWEEN TimeStart AND TimeEnd) OR (SchedTimeEnd3 BETWEEN TimeStart AND TimeEnd)
  120.             OR ((SchedTimeEnd3 > TimeStart AND SchedTimeEnd3
  121.             AND ((SchedTimeEnd3 > TimeStart AND SchedTimeEnd3
  122.  
  123.         /*----------------------------------*/  
  124.     UNION -- SCHEDULE.3 TO SCHEDULE.4
  125.         /*----------------------------------*/
  126.  
  127.      SELECT  SubjectOfferingID, CS.TermID, CS.SubjectID, S.SubjectCode, S.SubjectTitle, S.CreditUnits, CSec.SectionTitle,
  128.             CS.Sched1, fnRoomName2(CS.RoomID) AS Room_1,
  129.             CS.Sched2, fnRoomName2(CS.RoomID2) AS Room_2,
  130.             CS.Sched3, fnRoomName2(CS.RoomID3) AS Room_3,
  131.             CS.Sched4, fnRoomName2(CS.RoomID4) AS Room_4,
  132.             CS.Sched5, fnRoomName2(CS.RoomID5) AS Room_5,
  133.             fnProgramCode(CSec.ProgramID) AS ProgramCode
  134.     FROM    tblClassSchedule AS CS LEFT JOIN
  135.             tblSubject AS S ON S.SubjectID = CS.SubjectID LEFT JOIN
  136.             tblSection AS CSec ON CSec.SectionID = CS.SectionID
  137.     WHERE   (CS.TermID = TermID) AND
  138.             (CS.TeacherID4 = FacultyID) AND
  139.             (Days4 LIKE sDay) AND
  140.             ((SchedTimeStart4 BETWEEN TimeStart AND TimeEnd) OR (SchedTimeEnd4 BETWEEN TimeStart AND TimeEnd)
  141.             OR ((SchedTimeEnd4 > TimeStart AND SchedTimeEnd4
  142.             AND ((SchedTimeEnd4 > TimeStart AND SchedTimeEnd4
  143.  
  144.         /*----------------------------------*/      
  145.     UNION -- SCHEDULE.4 TO SCHEDULE.5
  146.         /*----------------------------------*/
  147.  
  148.      SELECT  SubjectOfferingID, CS.TermID, CS.SubjectID, S.SubjectCode, S.SubjectTitle, S.CreditUnits, CSec.SectionTitle,
  149.             CS.Sched1, fnRoomName2(CS.RoomID) AS Room_1,
  150.             CS.Sched2, fnRoomName2(CS.RoomID2) AS Room_2,
  151.             CS.Sched3, fnRoomName2(CS.RoomID3) AS Room_3,
  152.             CS.Sched4, fnRoomName2(CS.RoomID4) AS Room_4,
  153.             CS.Sched5, fnRoomName2(CS.RoomID5) AS Room_5,
  154.             fnProgramCode(CSec.ProgramID) AS ProgramCode
  155.     FROM    tblClassSchedule AS CS LEFT JOIN
  156.             tblSubject AS S ON S.SubjectID = CS.SubjectID LEFT JOIN
  157.             tblSection AS CSec ON CSec.SectionID = CS.SectionID
  158.     WHERE   (CS.TermID = TermID) AND
  159.             (CS.TeacherID5 = FacultyID) AND
  160.             (Days5 LIKE sDay) AND
  161.             ((SchedTimeStart5 BETWEEN TimeStart AND TimeEnd) OR (SchedTimeEnd5 BETWEEN TimeStart AND TimeEnd)
  162.             OR ((SchedTimeEnd5 > TimeStart AND SchedTimeEnd5
  163.             AND ((SchedTimeEnd5 > TimeStart AND SchedTimeEnd5
  164. END;
  165.  
  166. CREATE DEFINER = 'root'@'localhost' PROCEDURE `GetRoomScheduleConflicts`(
  167.         TermID  INT,
  168.         RoomID  VARCHAR(15),
  169.         sDay  VARCHAR(10),
  170.         TimeStart VARCHAR(10),
  171.         TimeEnd VARCHAR(10)
  172.     )
  173.     DETERMINISTIC
  174.     CONTAINS SQL
  175.     SQL SECURITY DEFINER
  176.     COMMENT ''
  177.  
  178. BEGIN
  179.  
  180.     SELECT  SubjectOfferingID, CS.TermID, CS.SubjectID, S.SubjectCode, S.SubjectTitle, S.CreditUnits, CSec.SectionTitle,
  181.             CS.Sched1, fnRoomName2(CS.RoomID) AS Room_1,
  182.             CS.Sched2, fnRoomName2(CS.RoomID2) AS Room_2,
  183.             CS.Sched3, fnRoomName2(CS.RoomID3) AS Room_3,
  184.             CS.Sched4, fnRoomName2(CS.RoomID4) AS Room_4,
  185.             CS.Sched5, fnRoomName2(CS.RoomID5) AS Room_5,
  186.             fnProgramCode(CSec.ProgramID) AS ProgramCode
  187.     FROM tblClassSchedule AS CS LEFT JOIN
  188.             tblSubject AS S ON S.SubjectID = CS.SubjectID LEFT JOIN
  189.             tblSection AS CSec ON CSec.SectionID = CS.SectionID
  190.     WHERE   (CS.TermID = TermID) AND
  191.             (CS.RoomID = RoomID) AND
  192.             (CS.Days LIKE sDay) AND
  193.             ((SchedTimeStart BETWEEN TimeStart AND TimeEnd) OR (SchedTimeEnd BETWEEN TimeStart AND TimeEnd)
  194.             OR ((SchedTimeEnd > TimeStart AND SchedTimeEnd
  195.             AND ((SchedTimeEnd > TimeStart AND SchedTimeEnd
  196.  
  197.         /*----------------------------------*/    
  198.     UNION -- SCHEDULE.1 TO SCHEDULE.2
  199.     /*----------------------------------*/
  200.  
  201.     SELECT  SubjectOfferingID, CS.TermID, CS.SubjectID, S.SubjectCode, S.SubjectTitle, S.CreditUnits, CSec.SectionTitle,
  202.             CS.Sched1, fnRoomName2(CS.RoomID) AS Room_1,
  203.             CS.Sched2, fnRoomName2(CS.RoomID2) AS Room_2,
  204.             CS.Sched3, fnRoomName2(CS.RoomID3) AS Room_3,
  205.             CS.Sched4, fnRoomName2(CS.RoomID4) AS Room_4,
  206.             CS.Sched5, fnRoomName2(CS.RoomID5) AS Room_5,
  207.             fnProgramCode(CSec.ProgramID) AS ProgramCode
  208.     FROM    tblClassSchedule AS CS LEFT JOIN
  209.             tblSubject AS S ON S.SubjectID = CS.SubjectID LEFT JOIN
  210.             tblSection AS CSec ON CSec.SectionID = CS.SectionID
  211.     WHERE   (CS.TermID = TermID) AND
  212.             (CS.RoomID2 = RoomID) AND
  213.             (Days2 LIKE sDay) AND
  214.             ((SchedTimeStart2 BETWEEN TimeStart AND TimeEnd) OR (SchedTimeEnd2 BETWEEN TimeStart AND TimeEnd)
  215.             OR ((SchedTimeEnd2 > TimeStart AND SchedTimeEnd2
  216.             AND ((SchedTimeEnd2 > TimeStart AND SchedTimeEnd2
  217.  
  218.         /*----------------------------------*/      
  219.     UNION -- SCHEDULE.2 TO SCHEDULE.3
  220.         /*----------------------------------*/
  221.  
  222.     SELECT  SubjectOfferingID, CS.TermID, CS.SubjectID, S.SubjectCode, S.SubjectTitle, S.CreditUnits, CSec.SectionTitle,
  223.             CS.Sched1, fnRoomName2(CS.RoomID) AS Room_1,
  224.             CS.Sched2, fnRoomName2(CS.RoomID2) AS Room_2,
  225.             CS.Sched3, fnRoomName2(CS.RoomID3) AS Room_3,
  226.             CS.Sched4, fnRoomName2(CS.RoomID4) AS Room_4,
  227.             CS.Sched5, fnRoomName2(CS.RoomID5) AS Room_5,
  228.             fnProgramCode(CSec.ProgramID) AS ProgramCode
  229.     FROM    tblClassSchedule AS CS LEFT JOIN
  230.             tblSubject AS S ON S.SubjectID = CS.SubjectID LEFT JOIN
  231.             tblSection AS CSec ON CSec.SectionID = CS.SectionID
  232.     WHERE   (CS.TermID = TermID) AND
  233.             (CS.RoomID3 = RoomID) AND
  234.             (Days3 LIKE sDay) AND
  235.             ((SchedTimeStart3 BETWEEN TimeStart AND TimeEnd) OR (SchedTimeEnd3 BETWEEN TimeStart AND TimeEnd)
  236.             OR ((SchedTimeEnd3 > TimeStart AND SchedTimeEnd3
  237.             AND ((SchedTimeEnd3 > TimeStart AND SchedTimeEnd3
  238.  
  239.         /*----------------------------------*/  
  240.     UNION -- SCHEDULE.3 TO SCHEDULE.4
  241.         /*----------------------------------*/
  242.  
  243.      SELECT  SubjectOfferingID, CS.TermID, CS.SubjectID, S.SubjectCode, S.SubjectTitle, S.CreditUnits, CSec.SectionTitle,
  244.             CS.Sched1, fnRoomName2(CS.RoomID) AS Room_1,
  245.             CS.Sched2, fnRoomName2(CS.RoomID2) AS Room_2,
  246.             CS.Sched3, fnRoomName2(CS.RoomID3) AS Room_3,
  247.             CS.Sched4, fnRoomName2(CS.RoomID4) AS Room_4,
  248.             CS.Sched5, fnRoomName2(CS.RoomID5) AS Room_5,
  249.             fnProgramCode(CSec.ProgramID) AS ProgramCode
  250.     FROM    tblClassSchedule AS CS LEFT JOIN
  251.             tblSubject AS S ON S.SubjectID = CS.SubjectID LEFT JOIN
  252.             tblSection AS CSec ON CSec.SectionID = CS.SectionID
  253.     WHERE   (CS.TermID = TermID) AND
  254.             (CS.RoomID4 = RoomID) AND
  255.             (Days4 LIKE sDay) AND
  256.             ((SchedTimeStart4 BETWEEN TimeStart AND TimeEnd) OR (SchedTimeEnd4 BETWEEN TimeStart AND TimeEnd)
  257.             OR ((SchedTimeEnd4 > TimeStart AND SchedTimeEnd4
  258.             AND ((SchedTimeEnd4 > TimeStart AND SchedTimeEnd4
  259.  
  260.  
  261.         /*----------------------------------*/      
  262.     UNION -- SCHEDULE.4 TO SCHEDULE.5
  263.         /*----------------------------------*/
  264.  
  265.      SELECT  SubjectOfferingID, CS.TermID, CS.SubjectID, S.SubjectCode, S.SubjectTitle, S.CreditUnits, CSec.SectionTitle,
  266.             CS.Sched1, fnRoomName2(CS.RoomID) AS Room_1,
  267.             CS.Sched2, fnRoomName2(CS.RoomID2) AS Room_2,
  268.             CS.Sched3, fnRoomName2(CS.RoomID3) AS Room_3,
  269.             CS.Sched4, fnRoomName2(CS.RoomID4) AS Room_4,
  270.             CS.Sched5, fnRoomName2(CS.RoomID5) AS Room_5,
  271.             fnProgramCode(CSec.ProgramID) AS ProgramCode
  272.     FROM    tblClassSchedule AS CS LEFT JOIN
  273.             tblSubject AS S ON S.SubjectID = CS.SubjectID LEFT JOIN
  274.             tblSection AS CSec ON CSec.SectionID = CS.SectionID
  275.     WHERE   (CS.TermID = TermID) AND
  276.             (CS.RoomID5 = RoomID) AND
  277.             (Days5 LIKE sDay) AND
  278.             ((SchedTimeStart5 BETWEEN TimeStart AND TimeEnd) OR (SchedTimeEnd5 BETWEEN TimeStart AND TimeEnd)
  279.             OR ((SchedTimeEnd5 > TimeStart AND SchedTimeEnd5
  280.             AND ((SchedTimeEnd5 > TimeStart AND SchedTimeEnd5
  281. END;
  282.  
  283.  
  284. /*=================== STORED FUNCTION ===========================*/
  285.  
  286. CREATE DEFINER = 'root'@'localhost' FUNCTION `fnProgramName`( ProgID INT )
  287.     RETURNS VARCHAR(100) CHARSET utf8
  288.     DETERMINISTIC
  289.     CONTAINS SQL
  290.     SQL SECURITY DEFINER
  291.     COMMENT ''
  292.  
  293. BEGIN
  294.  
  295.     DECLARE ProgramName VARCHAR(100);
  296.     SELECT Programs.ProgName INTO ProgramName  FROM  tblPrograms AS Programs WHERE Programs.ProgID = ProgID
  297.     LIMIT 1;
  298.  
  299.     RETURN ifnull(ProgramName,'');
  300. END;
  301.  
  302. CREATE DEFINER = 'root'@'localhost' FUNCTION `fnRoomName2`(
  303.         sRoomID VARCHAR(45)
  304.     )
  305.     RETURNS VARCHAR(60) CHARSET utf8
  306.     DETERMINISTIC
  307.     CONTAINS SQL
  308.     SQL SECURITY DEFINER
  309.     COMMENT ''
  310.        
  311. BEGIN
  312.  
  313.     DECLARE RoomName VARCHAR(60);
  314.     SELECT CONCAT(fnBuildingAcronym(R.BldgID) , '-' , R.Room) INTO RoomName FROM tblRoom AS R
  315.     WHERE R.RoomID = sRoomID LIMIT 1;
  316.     RETURN RoomName;
  317. END;

No offense, the author should have normalized some tables in the structure. The normalization process eliminates data redundancies and ensures logical data dependencies. For more on information on normalization, please try visit this address: http://databases.about.com/od/specificproducts/a/normalization.htm. Hope you find this helpful... magandang araw :)

Thank you for your suggestion...By the way Alam ko naman yung normalization... The truth behind normalization is hindi naman mag.eliminates ng data redundancies, kung hindi breaking down data warehousing to ensures logical data dependencies. Most of widely used software's today, most of them never apply normalization dahil ito ang pinagmumulan na tinatawag nating USER ERROR... Based on our experience, in providing School Management Solutions in the entire Philippines, NORMALIZATION is maririnig mo lang yan sa mga School, pero in Applied Software Engineering... bihira ka lang makakita ng mga ganyan.... =)

Actually the tblClassSchedule needs some tweaking, first things first, you should simplify the database structure for you to have a manageable records in which it will have the flexibility without overdoing it. Though i got your logic with the current table design, the consumption in memory of your stored procedure might produce some future errors. Fetching records will be slow as you pile-up records , try to study Database Modeling and Query Optimization. I already did 5+ scheduling system in the past both with Windows and Web based applications. (ASP.NET C#,C#.VB.NET,VB.6). As we all know, the the records per semester might eat around 50 to 200 mb or even more depends on the other records. imaginage a 5g of records after only 2 or 5 years of usage.

sir can you help me about the table structure of class scheduling on vb8 using sql server 2008 R2 as database,.!!thanks..,

Add new comment