Add foreign keys to databases.

This commit is contained in:
Gonne 2023-07-16 13:25:34 +02:00
parent 4ea0471683
commit 9632545d94
2 changed files with 35 additions and 26 deletions

View file

@ -1,8 +1,13 @@
DROP TABLE IF EXISTS `request`;
DROP TABLE IF EXISTS `officeHour`;
DROP TABLE IF EXISTS `room`;
DROP TABLE IF EXISTS `tutor`;
DROP TABLE IF EXISTS `course`;
-- --
-- Table structure for table `room` -- Table structure for table `room`
-- --
DROP TABLE IF EXISTS `room`;
CREATE TABLE `room` ( CREATE TABLE `room` (
`id` INTEGER PRIMARY KEY AUTO_INCREMENT, `id` INTEGER PRIMARY KEY AUTO_INCREMENT,
`name` text NOT NULL, `name` text NOT NULL,
@ -10,22 +15,28 @@ CREATE TABLE `room` (
); );
-- --
-- Table structure for table `request` -- Table structure for table `tutor`
-- --
DROP TABLE IF EXISTS `request`; CREATE TABLE `tutor` (
CREATE TABLE `request` (
`id` INTEGER PRIMARY KEY AUTO_INCREMENT, `id` INTEGER PRIMARY KEY AUTO_INCREMENT,
`officeHour` int DEFAULT NULL, `name` tinytext DEFAULT NULL,
`action` int DEFAULT NULL, `email` tinytext DEFAULT NULL
`secret` text DEFAULT NULL );
--
-- Table structure for table `course`
--
CREATE TABLE `course` (
`id` INTEGER PRIMARY KEY AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL
); );
-- --
-- Table structure for table `officeHour` -- Table structure for table `officeHour`
-- --
DROP TABLE IF EXISTS `officeHour`;
CREATE TABLE `officeHour` ( CREATE TABLE `officeHour` (
`id` INTEGER PRIMARY KEY AUTO_INCREMENT, `id` INTEGER PRIMARY KEY AUTO_INCREMENT,
`tutor` int DEFAULT NULL, `tutor` int DEFAULT NULL,
@ -38,26 +49,20 @@ CREATE TABLE `officeHour` (
`week` int DEFAULT NULL, `week` int DEFAULT NULL,
`info` text DEFAULT NULL, `info` text DEFAULT NULL,
`active` bool DEFAULT NULL, `active` bool DEFAULT NULL,
`duration` int DEFAULT NULL `duration` int DEFAULT NULL,
FOREIGN KEY (tutor) REFERENCES tutor(id),
FOREIGN KEY (room) REFERENCES room(id),
FOREIGN KEY (course) REFERENCES course(id)
); );
-- --
-- Table structure for table `tutor` -- Table structure for table `request`
-- --
DROP TABLE IF EXISTS `tutor`; CREATE TABLE `request` (
CREATE TABLE `tutor` (
`id` INTEGER PRIMARY KEY AUTO_INCREMENT, `id` INTEGER PRIMARY KEY AUTO_INCREMENT,
`name` tinytext DEFAULT NULL, `officeHour` int DEFAULT NULL,
`email` tinytext DEFAULT NULL `action` int DEFAULT NULL,
); `secret` tinytext DEFAULT NULL,
FOREIGN KEY (officeHour) REFERENCES officeHour(id)
--
-- Table structure for table `course`
--
DROP TABLE IF EXISTS `course`;
CREATE TABLE `course` (
`id` INTEGER PRIMARY KEY AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL
); );

View file

@ -18,7 +18,8 @@ CREATE TABLE `request` (
`id` INTEGER PRIMARY KEY, `id` INTEGER PRIMARY KEY,
`officeHour` int DEFAULT NULL, `officeHour` int DEFAULT NULL,
`action` int DEFAULT NULL, `action` int DEFAULT NULL,
`secret` text DEFAULT NULL `secret` text DEFAULT NULL,
FOREIGN KEY (officeHour) REFERENCES officeHour(id)
); );
-- --
@ -38,7 +39,10 @@ CREATE TABLE `officeHour` (
`week` int DEFAULT NULL, `week` int DEFAULT NULL,
`info` text DEFAULT NULL, `info` text DEFAULT NULL,
`active` bool DEFAULT NULL, `active` bool DEFAULT NULL,
`duration` int DEFAULT NULL `duration` int DEFAULT NULL,
FOREIGN KEY (tutor) REFERENCES tutor(id),
FOREIGN KEY (room) REFERENCES room(id),
FOREIGN KEY (course) REFERENCES course(id)
); );
-- --