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

START TRANSACTION;



--
-- Database: `louisxie_schedule`
--

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

--
-- Stand-in structure for view `combined_schedule`
-- (See below for the actual view)
--
CREATE TABLE `combined_schedule` (
`DATE` date
,`START TIME` varchar(7)
,`END TIME` varchar(7)
,`LOCATION` varchar(25)
,`TYPE` varchar(25)
,`TITLE` varchar(25)
);

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

--
-- Table structure for table `location`
--

CREATE TABLE `location` (
  `lct_id` int(11) NOT NULL,
  `lct` varchar(25) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `location`
--

INSERT INTO `location` (`lct_id`, `lct`) VALUES
(1, 'IYH212'),
(2, 'OHE540'),
(3, 'IYH111'),
(4, 'IYH210'),
(5, 'LVL3Y');

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

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

CREATE TABLE `schedule` (
  `date` date NOT NULL,
  `start_time` time NOT NULL,
  `end_time` time NOT NULL,
  `location` int(11) NOT NULL,
  `type` int(11) NOT NULL,
  `title` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `schedule`
--

INSERT INTO `schedule` (`date`, `start_time`, `end_time`, `location`, `type`, `title`) VALUES
('2023-09-11', '09:00:00', '12:00:00', 1, 1, 1),
('2023-09-13', '09:00:00', '12:00:00', 1, 1, 1),
('2023-09-18', '09:00:00', '12:00:00', 1, 1, 1),
('2023-09-20', '09:00:00', '12:00:00', 1, 1, 1),
('2023-09-25', '09:00:00', '12:00:00', 1, 1, 1),
('2023-09-27', '09:00:00', '12:00:00', 1, 1, 1),
('2023-10-02', '09:00:00', '12:00:00', 1, 1, 1),
('2023-10-04', '09:00:00', '12:00:00', 1, 1, 1),
('2023-09-11', '17:00:00', '19:00:00', 2, 2, 2),
('2023-09-13', '17:00:00', '19:00:00', 2, 2, 2),
('2023-09-18', '17:00:00', '19:00:00', 2, 2, 2),
('2023-09-20', '17:00:00', '19:00:00', 2, 2, 2),
('2023-09-25', '17:00:00', '19:00:00', 2, 2, 2),
('2023-09-27', '17:00:00', '19:00:00', 2, 2, 2),
('2023-10-02', '17:00:00', '19:00:00', 2, 2, 2),
('2023-10-04', '17:00:00', '19:00:00', 2, 2, 2),
('2023-09-12', '11:00:00', '13:00:00', 3, 1, 3),
('2023-09-14', '11:00:00', '13:00:00', 3, 1, 3),
('2023-09-19', '11:00:00', '13:00:00', 3, 1, 3),
('2023-09-21', '11:00:00', '13:00:00', 3, 1, 3),
('2023-09-26', '11:00:00', '13:00:00', 3, 1, 3),
('2023-09-28', '11:00:00', '13:00:00', 3, 1, 3),
('2023-10-03', '11:00:00', '13:00:00', 3, 1, 3),
('2023-10-05', '11:00:00', '13:00:00', 3, 1, 3),
('2023-09-12', '14:00:00', '17:00:00', 4, 1, 4),
('2023-09-14', '14:00:00', '17:00:00', 4, 1, 4),
('2023-09-19', '14:00:00', '17:00:00', 4, 1, 4),
('2023-09-21', '14:00:00', '17:00:00', 4, 1, 4),
('2023-09-26', '14:00:00', '17:00:00', 4, 1, 4),
('2023-09-28', '14:00:00', '17:00:00', 4, 1, 4),
('2023-10-03', '14:00:00', '17:00:00', 4, 1, 4),
('2023-10-05', '14:00:00', '17:00:00', 4, 1, 4),
('2023-09-14', '17:00:00', '19:00:00', 5, 1, 5),
('2023-09-21', '17:00:00', '19:00:00', 5, 1, 5),
('2023-09-28', '17:00:00', '19:00:00', 5, 1, 5),
('2023-10-05', '17:00:00', '19:00:00', 5, 1, 5);

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

--
-- Table structure for table `title`
--

CREATE TABLE `title` (
  `ttl_id` int(11) NOT NULL,
  `ttl` varchar(25) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `title`
--

INSERT INTO `title` (`ttl_id`, `ttl`) VALUES
(1, 'ACAD324'),
(2, 'ITP425'),
(3, 'ACAD499'),
(4, 'ACAD276'),
(5, 'SLL199');

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

--
-- Table structure for table `type`
--

CREATE TABLE `type` (
  `typ_id` int(11) NOT NULL,
  `typ` varchar(25) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `type`
--

INSERT INTO `type` (`typ_id`, `typ`) VALUES
(1, 'LECTURE'),
(2, 'LECTURE-LAB');

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

--
-- Structure for view `combined_schedule`
--

CREATE ALGORITHM=UNDEFINED DEFINER=`louisxie`@`localhost` SQL SECURITY DEFINER VIEW `combined_schedule`  AS SELECT `s`.`date` AS `DATE`, time_format(`s`.`start_time`,'%h:%i%p') AS `START TIME`, time_format(`s`.`end_time`,'%h:%i%p') AS `END TIME`, `l`.`lct` AS `LOCATION`, `t`.`typ` AS `TYPE`, `ttl`.`ttl` AS `TITLE` FROM (((`schedule` `s` join `location` `l` on((`s`.`location` = `l`.`lct_id`))) join `type` `t` on((`s`.`type` = `t`.`typ_id`))) join `title` `ttl` on((`s`.`title` = `ttl`.`ttl_id`))) ORDER BY `s`.`date` ASC, `s`.`start_time` ASC ;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `location`
--
ALTER TABLE `location`
  ADD PRIMARY KEY (`lct_id`);

--
-- Indexes for table `schedule`
--
ALTER TABLE `schedule`
  ADD KEY `location` (`location`),
  ADD KEY `title` (`title`),
  ADD KEY `type` (`type`);

--
-- Indexes for table `title`
--
ALTER TABLE `title`
  ADD PRIMARY KEY (`ttl_id`);

--
-- Indexes for table `type`
--
ALTER TABLE `type`
  ADD PRIMARY KEY (`typ_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `location`
--
ALTER TABLE `location`
  MODIFY `lct_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

--
-- AUTO_INCREMENT for table `title`
--
ALTER TABLE `title`
  MODIFY `ttl_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

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

--
-- Constraints for dumped tables
--

--
-- Constraints for table `schedule`
--
ALTER TABLE `schedule`
  ADD CONSTRAINT `schedule_ibfk_1` FOREIGN KEY (`location`) REFERENCES `location` (`lct_id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `schedule_ibfk_2` FOREIGN KEY (`title`) REFERENCES `title` (`ttl_id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `schedule_ibfk_3` FOREIGN KEY (`type`) REFERENCES `type` (`typ_id`) ON UPDATE CASCADE;
COMMIT;

