Skip to content

Instantly share code, notes, and snippets.

@rochajg
Last active September 7, 2021 02:23
Show Gist options
  • Select an option

  • Save rochajg/ca58245c4a82a5f1a9a1ea48e699f9f5 to your computer and use it in GitHub Desktop.

Select an option

Save rochajg/ca58245c4a82a5f1a9a1ea48e699f9f5 to your computer and use it in GitHub Desktop.
CREATE DATABASE IF NOT EXISTS `library`;
USE `library`;
--
-- Table structure for table `author`
--
DROP TABLE IF EXISTS `author`;
CREATE TABLE `author` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(150) NOT NULL,
`date_created` datetime NOT NULL,
`last_updated` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
--
-- Dumping data for table `author`
--
LOCK TABLES `author` WRITE;
INSERT INTO `author` VALUES (1,'Maischato de Assis','2021-09-06 22:54:56','2021-09-06 22:54:56');
UNLOCK TABLES;
--
-- Table structure for table `book`
--
DROP TABLE IF EXISTS `book`;
CREATE TABLE `book` (
`id` int NOT NULL AUTO_INCREMENT,
`title` varchar(150) NOT NULL,
`pages` int NOT NULL,
`release_date` datetime NOT NULL,
`id_category` int NOT NULL,
`id_publisher` int NOT NULL,
`date_created` datetime NOT NULL,
`last_updated` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id_UNIQUE` (`id`),
KEY `fk_category_idx` (`id_category`),
KEY `fk_publisher_idx` (`id_publisher`),
CONSTRAINT `fk_category` FOREIGN KEY (`id_category`) REFERENCES `category` (`id`),
CONSTRAINT `fk_publisher` FOREIGN KEY (`id_publisher`) REFERENCES `publisher` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
--
-- Dumping data for table `book`
--
LOCK TABLES `book` WRITE;
INSERT INTO `book` VALUES (2,'Memórias Prostumas de Brás Cuba',200,'2021-09-06 23:01:27',2,1,'2021-09-06 23:01:27','2021-09-06 23:01:27');
UNLOCK TABLES;
--
-- Table structure for table `book_author`
--
DROP TABLE IF EXISTS `book_author`;
CREATE TABLE `book_author` (
`id` int NOT NULL AUTO_INCREMENT,
`id_author` int NOT NULL,
`id_book` int NOT NULL,
PRIMARY KEY (`id`),
KEY `fk_author_idx` (`id_author`),
KEY `fk_book_idx` (`id_book`),
CONSTRAINT `fk_author` FOREIGN KEY (`id_author`) REFERENCES `author` (`id`),
CONSTRAINT `fk_book` FOREIGN KEY (`id_book`) REFERENCES `book` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
--
-- Dumping data for table `book_author`
--
LOCK TABLES `book_author` WRITE;
INSERT INTO `book_author` VALUES (2,1,2);
UNLOCK TABLES;
--
-- Table structure for table `category`
--
DROP TABLE IF EXISTS `category`;
CREATE TABLE `category` (
`id` int NOT NULL,
`name` varchar(150) NOT NULL,
`date_created` datetime NOT NULL,
`last_updated` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
--
-- Dumping data for table `category`
--
LOCK TABLES `category` WRITE;
INSERT INTO `category` VALUES (1,'Horror','2021-09-06 21:51:00','2021-09-06 21:52:56'),(2,'Fantasy','2021-09-06 21:57:54','2021-09-06 21:57:54'),(3,'Satanic','2021-09-06 21:59:53','2021-09-06 22:02:21');
UNLOCK TABLES;
--
-- Table structure for table `publisher`
--
DROP TABLE IF EXISTS `publisher`;
CREATE TABLE `publisher` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(150) NOT NULL,
`date_created` datetime NOT NULL,
`last_updated` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
--
-- Dumping data for table `publisher`
--
LOCK TABLES `publisher` WRITE;
INSERT INTO `publisher` VALUES (1,'Moderna','2021-09-06 22:57:05','2021-09-06 22:57:05');
UNLOCK TABLES;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment