-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdb.sql
More file actions
31 lines (27 loc) · 1 KB
/
db.sql
File metadata and controls
31 lines (27 loc) · 1 KB
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
create database `mydb` default character set utf8 COLLATE utf8_general_ci;
use `mydb`;
CREATE TABLE IF NOT EXISTS `country` (
`id` INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
`country` VARCHAR(60) NOT NULL,
UNIQUE INDEX `country_index` (`country`)
) Engine=InnoDB;
CREATE TABLE IF NOT EXISTS `city` (
`id` INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
`city` VARCHAR(100) NOT NULL,
`country_id` INTEGER,
FOREIGN KEY(`country_id`) REFERENCES `country`(`id`) ON DELETE SET NULL
ON UPDATE CASCADE,
UNIQUE INDEX `city_index` (`city`, `country_id`)
) Engine=InnoDB;
CREATE TABLE IF NOT EXISTS `users` (
`id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(60) NOT NULL,
`email` CHAR(255) NOT NULL,
`password` CHAR(32) NOT NULL,
`birth_date` DATE DEFAULT NULL,
`photo` TEXT DEFAULT NULL,
`city_id` INTEGER,
`gender` enum('male','female') NOT NULL DEFAULT 'male',
FOREIGN KEY(`city_id`) REFERENCES `city`(`id`) ON DELETE SET NULL ON UPDATE CASCADE,
UNIQUE INDEX `index1` (`email`)
) Engine=InnoDB;