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

START TRANSACTION;



--
-- Database: `daviddn_schedule`
--

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

--
-- Table structure for table `courses`
--

CREATE TABLE `courses` (
  `course_id` int(11) NOT NULL,
  `course_code` varchar(16) NOT NULL,
  `course_title` varchar(128) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `courses`
--

INSERT INTO `courses` (`course_id`, `course_code`, `course_title`) VALUES
(1, 'PSYC 100', 'Introduction to Psychology'),
(2, 'PHED 160', 'Stress Management for Healthy Living'),
(3, 'ACAD 276', 'Dev II'),
(4, 'BUAD 302', 'Communication Strategy in Business'),
(5, 'BUAD 306', 'Business Finance');

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

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

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

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

INSERT INTO `locations` (`location_id`, `location_name`) VALUES
(5, 'HOH 1'),
(3, 'IYH 210'),
(4, 'JFF 322'),
(2, 'KAP 145'),
(6, 'Online (Zoom)'),
(1, 'THH 101');

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

--
-- Table structure for table `meetings`
--

CREATE TABLE `meetings` (
  `meeting_id` int(11) NOT NULL,
  `meeting_date` date NOT NULL,
  `start_time` time NOT NULL,
  `end_time` time NOT NULL,
  `course_id` int(11) NOT NULL,
  `location_id` int(11) NOT NULL,
  `type_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `meetings`
--

INSERT INTO `meetings` (`meeting_id`, `meeting_date`, `start_time`, `end_time`, `course_id`, `location_id`, `type_id`) VALUES
(1, '2025-09-15', '10:00:00', '11:50:00', 1, 6, 1),
(2, '2025-09-15', '16:00:00', '16:50:00', 4, 4, 1),
(3, '2025-09-15', '18:30:00', '19:50:00', 5, 5, 1),
(4, '2025-09-16', '09:30:00', '10:50:00', 1, 1, 1),
(5, '2025-09-16', '12:00:00', '12:50:00', 2, 2, 1),
(6, '2025-09-16', '14:00:00', '15:30:00', 3, 3, 3),
(7, '2025-09-17', '09:30:00', '10:50:00', 1, 1, 1),
(8, '2025-09-18', '09:30:00', '10:50:00', 1, 1, 1),
(9, '2025-09-18', '12:00:00', '12:50:00', 2, 2, 1),
(10, '2025-09-18', '14:00:00', '15:30:00', 3, 3, 3),
(11, '2025-09-18', '16:00:00', '16:50:00', 4, 4, 1),
(12, '2025-09-18', '18:30:00', '19:50:00', 5, 5, 1),
(13, '2025-09-22', '10:00:00', '11:50:00', 1, 6, 1),
(14, '2025-09-22', '16:00:00', '16:50:00', 4, 4, 1),
(15, '2025-09-22', '18:30:00', '19:50:00', 5, 5, 1),
(16, '2025-09-23', '09:30:00', '10:50:00', 1, 1, 1),
(17, '2025-09-23', '12:00:00', '12:50:00', 2, 2, 1),
(18, '2025-09-23', '14:00:00', '15:30:00', 3, 3, 3),
(19, '2025-09-24', '09:30:00', '10:50:00', 1, 1, 1),
(20, '2025-09-25', '09:30:00', '10:50:00', 1, 1, 1),
(21, '2025-09-25', '12:00:00', '12:50:00', 2, 2, 1),
(22, '2025-09-25', '14:00:00', '15:30:00', 3, 3, 3),
(23, '2025-09-25', '16:00:00', '16:50:00', 4, 4, 1),
(24, '2025-09-25', '18:30:00', '19:50:00', 5, 5, 1),
(25, '2025-09-29', '10:00:00', '11:50:00', 1, 6, 1),
(26, '2025-09-29', '16:00:00', '16:50:00', 4, 4, 1),
(27, '2025-09-29', '18:30:00', '19:50:00', 5, 5, 1),
(28, '2025-09-30', '09:30:00', '10:50:00', 1, 1, 1),
(29, '2025-09-30', '12:00:00', '12:50:00', 2, 2, 1),
(30, '2025-09-30', '14:00:00', '15:30:00', 3, 3, 3),
(31, '2025-10-01', '09:30:00', '10:50:00', 1, 1, 1),
(32, '2025-10-02', '09:30:00', '10:50:00', 1, 1, 1),
(33, '2025-10-02', '12:00:00', '12:50:00', 2, 2, 1),
(34, '2025-10-02', '14:00:00', '15:30:00', 3, 3, 3),
(35, '2025-10-02', '16:00:00', '16:50:00', 4, 4, 1),
(36, '2025-10-02', '18:30:00', '19:50:00', 5, 5, 1),
(37, '2025-10-06', '10:00:00', '11:50:00', 1, 6, 1),
(38, '2025-10-06', '16:00:00', '16:50:00', 4, 4, 1),
(39, '2025-10-06', '18:30:00', '19:50:00', 5, 5, 1),
(40, '2025-10-07', '09:30:00', '10:50:00', 1, 1, 1),
(41, '2025-10-07', '12:00:00', '12:50:00', 2, 2, 1),
(42, '2025-10-07', '14:00:00', '15:30:00', 3, 3, 3),
(43, '2025-10-08', '09:30:00', '10:50:00', 1, 1, 1),
(44, '2025-10-09', '09:30:00', '10:50:00', 1, 1, 1),
(45, '2025-10-09', '12:00:00', '12:50:00', 2, 2, 1),
(46, '2025-10-09', '14:00:00', '15:30:00', 3, 3, 3),
(47, '2025-10-09', '16:00:00', '16:50:00', 4, 4, 1),
(48, '2025-10-09', '18:30:00', '19:50:00', 5, 5, 1);

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

--
-- Table structure for table `meeting_types`
--

CREATE TABLE `meeting_types` (
  `type_id` int(11) NOT NULL,
  `type_name` varchar(32) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `meeting_types`
--

INSERT INTO `meeting_types` (`type_id`, `type_name`) VALUES
(2, 'Lab'),
(1, 'Lecture'),
(3, 'Lecture/Lab');

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

--
-- Stand-in structure for view `v_schedule`
-- (See below for the actual view)
--
CREATE TABLE `v_schedule` (
`date` date
,`start` varchar(7)
,`end` varchar(7)
,`location` varchar(64)
,`type` varchar(32)
,`course` varchar(146)
);

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

--
-- Structure for view `v_schedule`
--

CREATE ALGORITHM=UNDEFINED DEFINER=`daviddn`@`localhost` SQL SECURITY DEFINER VIEW `v_schedule`  AS SELECT `m`.`meeting_date` AS `date`, date_format(`m`.`start_time`,'%l:%i%p') AS `start`, date_format(`m`.`end_time`,'%l:%i%p') AS `end`, `l`.`location_name` AS `location`, `mt`.`type_name` AS `type`, concat(`c`.`course_code`,': ',`c`.`course_title`) AS `course` FROM (((`meetings` `m` join `courses` `c` on((`m`.`course_id` = `c`.`course_id`))) join `locations` `l` on((`m`.`location_id` = `l`.`location_id`))) join `meeting_types` `mt` on((`m`.`type_id` = `mt`.`type_id`))) ORDER BY `m`.`meeting_date` ASC, `m`.`start_time` ASC ;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `courses`
--
ALTER TABLE `courses`
  ADD PRIMARY KEY (`course_id`),
  ADD UNIQUE KEY `uq_course_code` (`course_code`);

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

--
-- Indexes for table `meetings`
--
ALTER TABLE `meetings`
  ADD PRIMARY KEY (`meeting_id`),
  ADD KEY `fk_meet_course` (`course_id`),
  ADD KEY `fk_meet_location` (`location_id`),
  ADD KEY `fk_meet_type` (`type_id`),
  ADD KEY `ix_meet_date_time` (`meeting_date`,`start_time`);

--
-- Indexes for table `meeting_types`
--
ALTER TABLE `meeting_types`
  ADD PRIMARY KEY (`type_id`),
  ADD UNIQUE KEY `type_name` (`type_name`);

--
-- AUTO_INCREMENT for dumped tables
--

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

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

--
-- AUTO_INCREMENT for table `meetings`
--
ALTER TABLE `meetings`
  MODIFY `meeting_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=49;

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

--
-- Constraints for dumped tables
--

--
-- Constraints for table `meetings`
--
ALTER TABLE `meetings`
  ADD CONSTRAINT `fk_meet_course` FOREIGN KEY (`course_id`) REFERENCES `courses` (`course_id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_meet_location` FOREIGN KEY (`location_id`) REFERENCES `locations` (`location_id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_meet_type` FOREIGN KEY (`type_id`) REFERENCES `meeting_types` (`type_id`) ON UPDATE CASCADE;
COMMIT;

