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`
--
DROP TABLE IF EXISTS `room`;
CREATE TABLE `room` (
`id` INTEGER PRIMARY KEY AUTO_INCREMENT,
`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 `request` (
CREATE TABLE `tutor` (
`id` INTEGER PRIMARY KEY AUTO_INCREMENT,
`officeHour` int DEFAULT NULL,
`action` int DEFAULT NULL,
`secret` text DEFAULT NULL
`name` tinytext DEFAULT NULL,
`email` tinytext 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`
--
DROP TABLE IF EXISTS `officeHour`;
CREATE TABLE `officeHour` (
`id` INTEGER PRIMARY KEY AUTO_INCREMENT,
`tutor` int DEFAULT NULL,
@ -38,26 +49,20 @@ CREATE TABLE `officeHour` (
`week` int DEFAULT NULL,
`info` text 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 `tutor` (
CREATE TABLE `request` (
`id` INTEGER PRIMARY KEY AUTO_INCREMENT,
`name` tinytext DEFAULT NULL,
`email` tinytext DEFAULT NULL
);
--
-- Table structure for table `course`
--
DROP TABLE IF EXISTS `course`;
CREATE TABLE `course` (
`id` INTEGER PRIMARY KEY AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL
`officeHour` int DEFAULT NULL,
`action` int DEFAULT NULL,
`secret` tinytext DEFAULT NULL,
FOREIGN KEY (officeHour) REFERENCES officeHour(id)
);

View file

@ -18,7 +18,8 @@ CREATE TABLE `request` (
`id` INTEGER PRIMARY KEY,
`officeHour` 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,
`info` text 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)
);
--