-- https://www.phpmyadmin.net/
--

START TRANSACTION;



--
-- Database: `apchang_schedule`
--

-- --------------------------------------------------------

--
-- Table structure for table `classnames`
--

CREATE TABLE `classnames` (
  `class_id` int(11) NOT NULL,
  `class` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `classnames`
--

INSERT INTO `classnames` (`class_id`, `class`) VALUES
(1, 'Acad276: Dev 2'),
(2, 'Acad245: Fundamentals of Product Design'),
(3, 'Acad324: The Practice of Design: Ideation to Innovation'),
(4, 'Bisc230: The Biology of the Brain (Lab)'),
(5, 'Bisc230: The Biology of the Brain (Lec)'),
(30, 'dev4'),
(31, 'dev4');

-- --------------------------------------------------------

--
-- Table structure for table `rooms`
--

CREATE TABLE `rooms` (
  `room_id` int(11) NOT NULL,
  `room` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `rooms`
--

INSERT INTO `rooms` (`room_id`, `room`) VALUES
(1, 'IYH210'),
(2, 'IYH110'),
(3, 'IYH212/213'),
(4, 'ZHS372'),
(5, 'MHPB7B'),
(6, 'newroomname'),
(7, 'newroomname'),
(8, 'newroomname'),
(9, 'newroomname'),
(10, 'newroomname'),
(11, 'newroomname'),
(12, 'newroomname'),
(13, 'newroomname');

-- --------------------------------------------------------

--
-- Stand-in structure for view `scheduleView`
-- (See below for the actual view)
--
CREATE TABLE `scheduleView` (
`schedule_id` int(11)
,`date` date
,`start` time
,`end` time
,`room_id` int(11)
,`type_id` int(11)
,`class_id` int(11)
,`class` varchar(100)
,`room` varchar(50)
,`type` varchar(50)
);

-- --------------------------------------------------------

--
-- Table structure for table `schedule_main`
--

CREATE TABLE `schedule_main` (
  `schedule_id` int(11) NOT NULL,
  `date` date NOT NULL,
  `start` time NOT NULL,
  `end` time NOT NULL,
  `room_id` int(11) NOT NULL,
  `type_id` int(11) NOT NULL,
  `class_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `schedule_main`
--

INSERT INTO `schedule_main` (`schedule_id`, `date`, `start`, `end`, `room_id`, `type_id`, `class_id`) VALUES
(1, '2024-09-17', '14:00:00', '16:50:00', 1, 1, 1),
(2, '2024-09-19', '14:00:00', '16:50:00', 1, 1, 1),
(3, '2024-09-16', '09:00:00', '11:50:00', 2, 1, 2),
(4, '2024-09-18', '09:00:00', '11:50:00', 2, 1, 2),
(5, '2024-09-17', '09:00:00', '11:50:00', 3, 2, 3),
(6, '2024-09-19', '09:00:00', '11:50:00', 3, 2, 3),
(7, '2024-09-16', '13:00:00', '14:50:00', 4, 3, 4),
(8, '2024-09-16', '15:00:00', '15:50:00', 5, 2, 5),
(9, '2024-09-18', '15:00:00', '15:50:00', 5, 2, 5),
(10, '2024-09-20', '15:00:00', '15:50:00', 5, 2, 5),
(11, '2024-09-24', '14:00:00', '16:50:00', 1, 1, 1),
(12, '2024-09-26', '14:00:00', '16:50:00', 1, 1, 1),
(13, '2024-09-23', '09:00:00', '11:50:00', 2, 1, 2),
(14, '2024-09-25', '09:00:00', '11:50:00', 2, 1, 2),
(15, '2024-09-24', '09:00:00', '11:50:00', 3, 2, 3),
(16, '2024-09-26', '09:00:00', '11:50:00', 3, 2, 3),
(17, '2024-09-23', '13:00:00', '14:50:00', 4, 3, 4),
(18, '2024-09-23', '15:00:00', '15:50:00', 5, 2, 5),
(19, '2024-09-25', '15:00:00', '15:50:00', 5, 2, 5),
(20, '2024-09-27', '15:00:00', '15:50:00', 5, 2, 5),
(21, '2024-10-01', '14:00:00', '16:50:00', 1, 1, 1),
(22, '2024-10-03', '14:00:00', '16:50:00', 1, 1, 1),
(23, '2024-09-30', '09:00:00', '11:50:00', 2, 1, 2),
(24, '2024-10-02', '09:00:00', '11:50:00', 2, 1, 2),
(25, '2024-10-01', '09:00:00', '11:50:00', 3, 2, 3),
(26, '2024-10-03', '09:00:00', '11:50:00', 3, 2, 3),
(27, '2024-09-30', '13:00:00', '14:50:00', 4, 3, 4),
(28, '2024-09-30', '15:00:00', '15:50:00', 5, 2, 5),
(29, '2024-10-02', '15:00:00', '15:50:00', 5, 2, 5),
(30, '2024-10-04', '15:00:00', '15:50:00', 5, 2, 5),
(31, '2024-10-08', '14:00:00', '16:50:00', 1, 1, 1),
(32, '2024-10-10', '14:00:00', '16:50:00', 1, 1, 1),
(33, '2024-10-07', '09:00:00', '11:50:00', 2, 1, 2),
(34, '2024-10-09', '09:00:00', '11:50:00', 2, 1, 2),
(35, '2024-10-08', '09:00:00', '11:50:00', 3, 2, 3),
(36, '2024-10-10', '09:00:00', '11:50:00', 3, 2, 3),
(37, '2024-10-07', '13:00:00', '14:50:00', 4, 3, 4),
(38, '2024-10-07', '15:00:00', '15:50:00', 5, 2, 5),
(39, '2024-10-09', '15:00:00', '15:50:00', 5, 2, 5),
(40, '2024-10-11', '15:00:00', '15:50:00', 5, 2, 5);

-- --------------------------------------------------------

--
-- Stand-in structure for view `schedule_view`
-- (See below for the actual view)
--
CREATE TABLE `schedule_view` (
`schedule_id` int(11)
,`date` date
,`start` time
,`end` time
,`room_id` int(11)
,`type_id` int(11)
,`class_id` int(11)
);

-- --------------------------------------------------------

--
-- Table structure for table `types`
--

CREATE TABLE `types` (
  `type_id` int(11) NOT NULL,
  `type` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `types`
--

INSERT INTO `types` (`type_id`, `type`) VALUES
(1, 'Lecture/Lab'),
(2, 'Lecture'),
(3, 'Lab'),
(4, 'newlecture'),
(5, 'newlecture'),
(6, 'newlecture'),
(7, 'newlecture'),
(8, 'newlecture'),
(9, 'newlecture'),
(10, 'newlecture'),
(11, 'newlecture');

-- --------------------------------------------------------

--
-- Structure for view `scheduleView`
--

CREATE ALGORITHM=UNDEFINED DEFINER=`apchang`@`localhost` SQL SECURITY DEFINER VIEW `scheduleView`  AS SELECT `schedule_main`.`schedule_id` AS `schedule_id`, `schedule_main`.`date` AS `date`, `schedule_main`.`start` AS `start`, `schedule_main`.`end` AS `end`, `schedule_main`.`room_id` AS `room_id`, `schedule_main`.`type_id` AS `type_id`, `schedule_main`.`class_id` AS `class_id`, `classnames`.`class` AS `class`, `rooms`.`room` AS `room`, `types`.`type` AS `type` FROM (((`schedule_main` join `classnames`) join `rooms`) join `types`) WHERE ((`schedule_main`.`room_id` = `rooms`.`room_id`) AND (`schedule_main`.`class_id` = `classnames`.`class_id`) AND (`schedule_main`.`type_id` = `types`.`type_id`)) ;

-- --------------------------------------------------------

--
-- Structure for view `schedule_view`
--

CREATE ALGORITHM=UNDEFINED DEFINER=`apchang`@`localhost` SQL SECURITY DEFINER VIEW `schedule_view`  AS SELECT `schedule_main`.`schedule_id` AS `schedule_id`, `schedule_main`.`date` AS `date`, `schedule_main`.`start` AS `start`, `schedule_main`.`end` AS `end`, `schedule_main`.`room_id` AS `room_id`, `schedule_main`.`type_id` AS `type_id`, `schedule_main`.`class_id` AS `class_id` FROM `schedule_main` ;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `classnames`
--
ALTER TABLE `classnames`
  ADD PRIMARY KEY (`class_id`);

--
-- Indexes for table `rooms`
--
ALTER TABLE `rooms`
  ADD PRIMARY KEY (`room_id`);

--
-- Indexes for table `schedule_main`
--
ALTER TABLE `schedule_main`
  ADD PRIMARY KEY (`schedule_id`),
  ADD KEY `schedule_main_ibfk_1` (`class_id`),
  ADD KEY `schedule_main_ibfk_3` (`type_id`),
  ADD KEY `schedule_main_ibfk_2` (`room_id`,`type_id`,`class_id`) USING BTREE;

--
-- Indexes for table `types`
--
ALTER TABLE `types`
  ADD PRIMARY KEY (`type_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `classnames`
--
ALTER TABLE `classnames`
  MODIFY `class_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=32;

--
-- AUTO_INCREMENT for table `rooms`
--
ALTER TABLE `rooms`
  MODIFY `room_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=14;

--
-- AUTO_INCREMENT for table `schedule_main`
--
ALTER TABLE `schedule_main`
  MODIFY `schedule_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=90;

--
-- AUTO_INCREMENT for table `types`
--
ALTER TABLE `types`
  MODIFY `type_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=12;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `schedule_main`
--
ALTER TABLE `schedule_main`
  ADD CONSTRAINT `schedule_main_ibfk_1` FOREIGN KEY (`class_id`) REFERENCES `classnames` (`class_id`),
  ADD CONSTRAINT `schedule_main_ibfk_2` FOREIGN KEY (`room_id`) REFERENCES `rooms` (`room_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `schedule_main_ibfk_3` FOREIGN KEY (`type_id`) REFERENCES `types` (`type_id`);
COMMIT;

