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

START TRANSACTION;



--
-- Database: `jhpoon_schedule`
--

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

--
-- Table structure for table `classes`
--

CREATE TABLE `classes` (
  `class_id` int(11) NOT NULL,
  `class` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `classes`
--

INSERT INTO `classes` (`class_id`, `class`) VALUES
(1, 'The Practice of Design: Ideation to Innovation'),
(2, 'Language and Society'),
(3, 'Dev II'),
(4, 'Materials: Denim to Nanotubes');

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

--
-- Table structure for table `locations`
--

CREATE TABLE `locations` (
  `location_id` int(11) NOT NULL,
  `location` varchar(45) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `locations`
--

INSERT INTO `locations` (`location_id`, `location`) VALUES
(1, 'IYH212/213'),
(2, 'GFS106'),
(3, 'IYH210/211'),
(4, 'DMC202');

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

--
-- Table structure for table `schedule`
--

CREATE TABLE `schedule` (
  `schedule_id` int(11) NOT NULL,
  `date` date NOT NULL,
  `starttime` time NOT NULL,
  `endtime` time NOT NULL,
  `location_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`
--

INSERT INTO `schedule` (`schedule_id`, `date`, `starttime`, `endtime`, `location_id`, `type_id`, `class_id`) VALUES
(1, '2023-08-21', '09:00:00', '11:50:00', 1, 1, 1),
(2, '2023-08-22', '12:30:00', '13:50:00', 2, 1, 2),
(3, '2023-08-22', '14:00:00', '16:50:00', 3, 1, 3),
(4, '2023-08-22', '18:00:00', '19:50:00', 1, 1, 4),
(5, '2023-08-23', '09:00:00', '11:50:00', 1, 1, 1),
(6, '2023-08-24', '12:30:00', '13:50:00', 2, 1, 2),
(7, '2023-08-24', '14:00:00', '16:50:00', 3, 1, 3),
(8, '2023-08-24', '18:00:00', '19:50:00', 1, 1, 4),
(9, '2023-08-25', '09:00:00', '09:50:00', 4, 2, 2),
(10, '2023-08-28', '09:00:00', '11:50:00', 1, 1, 1),
(11, '2023-08-29', '12:30:00', '13:50:00', 2, 1, 2),
(12, '2023-08-29', '14:00:00', '16:50:00', 3, 1, 3),
(13, '2023-08-29', '18:00:00', '19:50:00', 1, 1, 4),
(14, '2023-08-30', '09:00:00', '11:50:00', 1, 1, 1),
(15, '2023-08-31', '12:30:00', '13:50:00', 2, 1, 2),
(16, '2023-08-31', '14:00:00', '16:50:00', 3, 1, 3),
(17, '2023-08-31', '18:00:00', '19:50:00', 1, 1, 4),
(18, '2023-09-01', '09:00:00', '09:50:00', 4, 2, 2),
(19, '2023-09-05', '12:30:00', '13:50:00', 2, 1, 2),
(20, '2023-09-05', '14:00:00', '16:50:00', 3, 1, 3),
(21, '2023-09-05', '18:00:00', '19:50:00', 1, 1, 4),
(22, '2023-09-06', '09:00:00', '11:50:00', 1, 1, 1),
(23, '2023-09-07', '12:30:00', '13:50:00', 2, 1, 2),
(24, '2023-09-07', '14:00:00', '16:50:00', 3, 1, 3),
(25, '2023-09-07', '18:00:00', '19:50:00', 1, 1, 4),
(26, '2023-09-08', '09:00:00', '09:50:00', 4, 2, 2),
(27, '2023-09-11', '09:00:00', '11:50:00', 1, 1, 1),
(28, '2023-09-12', '12:30:00', '13:50:00', 2, 1, 2),
(29, '2023-09-12', '14:00:00', '16:50:00', 3, 1, 3),
(30, '2023-09-12', '18:00:00', '19:50:00', 1, 1, 4),
(31, '2023-09-13', '09:00:00', '11:50:00', 1, 1, 1),
(32, '2023-09-14', '12:30:00', '13:50:00', 2, 1, 2),
(33, '2023-09-14', '14:00:00', '16:50:00', 3, 1, 3),
(34, '2023-09-14', '18:00:00', '19:50:00', 1, 1, 4),
(35, '2023-09-15', '09:00:00', '09:50:00', 4, 2, 2);

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

--
-- Stand-in structure for view `schedule_normal`
-- (See below for the actual view)
--
CREATE TABLE `schedule_normal` (
`date` date
,`starttime` time
,`endtime` time
,`location` varchar(45)
,`type` text
,`class` text
);

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

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

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

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

INSERT INTO `types` (`type_id`, `type`) VALUES
(1, 'Lecture'),
(2, 'Discussion');

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

--
-- Structure for view `schedule_normal`
--

CREATE ALGORITHM=UNDEFINED DEFINER=`jhpoon`@`%` SQL SECURITY DEFINER VIEW `schedule_normal`  AS SELECT `schedule`.`date` AS `date`, `schedule`.`starttime` AS `starttime`, `schedule`.`endtime` AS `endtime`, `locations`.`location` AS `location`, `types`.`type` AS `type`, `classes`.`class` AS `class` FROM (((`schedule` join `locations`) join `types`) join `classes`) WHERE ((`schedule`.`location_id` = `locations`.`location_id`) AND (`schedule`.`type_id` = `types`.`type_id`) AND (`schedule`.`class_id` = `classes`.`class_id`)) ORDER BY `schedule`.`date` ASC ;

--
-- Indexes for dumped tables
--

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

--
-- Indexes for table `locations`
--
ALTER TABLE `locations`
  ADD PRIMARY KEY (`location_id`);

--
-- Indexes for table `schedule`
--
ALTER TABLE `schedule`
  ADD PRIMARY KEY (`schedule_id`),
  ADD KEY `location` (`location_id`),
  ADD KEY `class` (`class_id`),
  ADD KEY `type` (`type_id`);

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

--
-- AUTO_INCREMENT for dumped tables
--

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

--
-- AUTO_INCREMENT for table `locations`
--
ALTER TABLE `locations`
  MODIFY `location_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

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

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

--
-- Constraints for dumped tables
--

--
-- Constraints for table `schedule`
--
ALTER TABLE `schedule`
  ADD CONSTRAINT `class` FOREIGN KEY (`class_id`) REFERENCES `classes` (`class_id`),
  ADD CONSTRAINT `location` FOREIGN KEY (`location_id`) REFERENCES `locations` (`location_id`),
  ADD CONSTRAINT `type` FOREIGN KEY (`type_id`) REFERENCES `types` (`type_id`);
COMMIT;

