2
-- Host: localhost Database: test
3
-- ------------------------------------------------------
4
-- Server version 5.1.53-log
6
SET FOREIGN_KEY_CHECKS=0;
8
DROP TABLE IF EXISTS `address`;
9
CREATE TABLE `address` (
10
`address_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
11
`address` varchar(50) NOT NULL,
12
`city_id` smallint(5) unsigned NOT NULL,
13
PRIMARY KEY (`address_id`),
14
KEY `idx_fk_city_id` (`city_id`),
15
CONSTRAINT `fk_address_city` FOREIGN KEY (`city_id`) REFERENCES `city` (`city_id`) ON UPDATE CASCADE
16
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
18
DROP TABLE IF EXISTS `city`;
20
`city_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
21
`city` varchar(50) NOT NULL,
22
`country_id` smallint(5) unsigned NOT NULL,
23
PRIMARY KEY (`city_id`),
24
KEY `idx_fk_country_id` (`country_id`),
25
CONSTRAINT `fk_city_country` FOREIGN KEY (`country_id`) REFERENCES `country` (`country_id`) ON UPDATE CASCADE
26
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
28
DROP TABLE IF EXISTS `country`;
29
CREATE TABLE `country` (
30
`country_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
31
`country` varchar(50) NOT NULL,
32
PRIMARY KEY (`country_id`)
33
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
35
DROP TABLE IF EXISTS `denorm_address`;
36
CREATE TABLE `denorm_address` (
37
`address_id` smallint(5) unsigned NOT NULL,
38
`address` varchar(50) NOT NULL,
39
`city_id` smallint(5) unsigned NOT NULL,
40
`city` varchar(50) NOT NULL,
41
`country_id` smallint(5) unsigned NOT NULL,
42
`country` varchar(50) NOT NULL,
43
PRIMARY KEY (`address_id`,`city_id`,`country_id`)
44
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
46
LOCK TABLES `denorm_address` WRITE;
47
INSERT INTO `denorm_address` VALUES
48
(1,'47 MySakila Drive',300,'Lethbridge',20,'Canada'),
49
(2,'28 MySQL Boulevard',576,'Woodridge',8,'Australia'),
50
(3,'23 Workhaven Lane',300,'Lethbridge',20,'Canada'),
51
(4,'1411 Lillydale Drive',576,'Woodridge',8,'Australia'),
52
(5,'1913 Hanoi Way',463,'Sasebo',50,'Japan'),
53
(6,'1121 Loja Avenue',449,'San Bernardino',103,'United States'),
54
(7,'692 Joliet Street',38,'Athenai',39,'Greece'),
55
(8,'1566 Inegl Manor',349,'Myingyan',64,'Myanmar'),
56
(9,'53 Idfu Parkway',361,'Nantou',92,'Taiwan'),
57
(10,'1795 Santiago Way',295,'Laredo',103,'United States');
60
SET FOREIGN_KEY_CHECKS=1;