-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.sql
50 lines (45 loc) · 1.83 KB
/
create.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
DROP DATABASE IF EXISTS bookstore;
CREATE DATABASE bookstore;
USE bookstore;
CREATE TABLE `authors` (
`author_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`nationality` varchar(100) DEFAULT NULL,
PRIMARY KEY (`author_id`),
UNIQUE KEY `uniq_author` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=193 DEFAULT CHARSET=utf8;
CREATE TABLE `books` (
`book_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`author_id` int(10) unsigned DEFAULT NULL,
`title` varchar(100) NOT NULL,
`year` int(11) NOT NULL DEFAULT '1900',
`language` varchar(2) NOT NULL COMMENT 'ISO 639-1 Language code (2 chars)',
`cover_url` varchar(500) DEFAULT NULL,
`price` double(6,2) DEFAULT NULL,
`sellable` tinyint(1) NOT NULL DEFAULT '0',
`copies` int(11) NOT NULL DEFAULT '1',
`description` text,
PRIMARY KEY (`book_id`),
UNIQUE KEY `book_language` (`title`,`language`)
) ENGINE=InnoDB AUTO_INCREMENT=199 DEFAULT CHARSET=utf8;
CREATE TABLE `clients` (
`client_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(50) DEFAULT NULL,
`email` varchar(100) NOT NULL,
`birthdate` date DEFAULT NULL,
`gender` enum('M','F') DEFAULT NULL,
`active` tinyint(1) NOT NULL DEFAULT '1',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`client_id`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=101 DEFAULT CHARSET=utf8;
CREATE TABLE `transactions` (
`transaction_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`book_id` int(10) unsigned NOT NULL,
`client_id` int(10) unsigned NOT NULL,
`type` enum('lend','sell') NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`modified_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`finished` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`transaction_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;