Created
July 10, 2023 22:55
-
-
Save isaacbatst/6c58c52c3fc4c64b36aff2c581354f26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE DATABASE library; | |
USE library; | |
CREATE TABLE categories ( | |
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, | |
name VARCHAR(100) NOT NULL | |
); | |
CREATE TABLE clients ( | |
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, | |
name VARCHAR(100) NOT NULL | |
); | |
CREATE TABLE authors ( | |
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, | |
name VARCHAR(100) NOT NULL, | |
author_status ENUM('alive', 'deceased') NOT NULL | |
); | |
CREATE TABLE books ( | |
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, | |
title VARCHAR(100) NOT NULL, | |
author_id INT UNSIGNED NOT NULL, | |
category_id INT UNSIGNED NOT NULL, | |
FOREIGN KEY (author_id) REFERENCES authors (id), | |
FOREIGN KEY (category_id) REFERENCES categories (id) | |
); | |
CREATE TABLE clients_books ( | |
client_id INT UNSIGNED, | |
book_id INT UNSIGNED, | |
FOREIGN KEY (client_id) REFERENCES clients (id), | |
FOREIGN KEY (book_id) REFERENCES books (id), | |
PRIMARY KEY(client_id, book_id) | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment