· 9 years ago · Feb 02, 2017, 08:56 PM
1CREATE TABLE IF NOT EXISTS `projectx`.`restaurants` (
2 `restaurant_id` INT NOT NULL AUTO_INCREMENT COMMENT '',
3 `restaurant_name` VARCHAR(45) NOT NULL COMMENT '',
4 PRIMARY KEY (`restaurant_id`) COMMENT '',
5 UNIQUE INDEX `restaurant_id_UNIQUE` (`restaurant_id` ASC) COMMENT '')
6ENGINE = InnoDB;
7
8
9-- -----------------------------------------------------
10-- Table `projectx`.`table_area`
11-- -----------------------------------------------------
12CREATE TABLE IF NOT EXISTS `projectx`.`table_area` (
13 `area_id` INT NOT NULL AUTO_INCREMENT COMMENT '',
14 `width` INT NOT NULL COMMENT '',
15 `height` INT NOT NULL COMMENT '',
16 PRIMARY KEY (`area_id`) COMMENT '',
17 UNIQUE INDEX `area_id_UNIQUE` (`area_id` ASC) COMMENT '')
18ENGINE = InnoDB;
19
20
21-- -----------------------------------------------------
22-- Table `projectx`.`table_position`
23-- -----------------------------------------------------
24CREATE TABLE IF NOT EXISTS `projectx`.`table_position` (
25 `position_id` INT NOT NULL AUTO_INCREMENT COMMENT '',
26 `pos_x` INT NOT NULL COMMENT '',
27 `pos_y` INT NOT NULL COMMENT '',
28 PRIMARY KEY (`position_id`) COMMENT '',
29 UNIQUE INDEX `position_id_UNIQUE` (`position_id` ASC) COMMENT '')
30ENGINE = InnoDB;
31
32
33-- -----------------------------------------------------
34-- Table `projectx`.`restaurant_tables`
35-- -----------------------------------------------------
36CREATE TABLE IF NOT EXISTS `projectx`.`restaurant_tables` (
37 `id` INT NOT NULL AUTO_INCREMENT COMMENT '',
38 `table_id` INT NOT NULL COMMENT '',
39 `restaurant_id` INT NOT NULL COMMENT '',
40 `table_kind` VARCHAR(10) NULL COMMENT '',
41 `number_of_seats` INT NOT NULL COMMENT '',
42 `is_taken` TINYINT(1) NOT NULL COMMENT '',
43 `table_area_id` INT NOT NULL COMMENT '',
44 `table_position_id` INT NOT NULL COMMENT '',
45 PRIMARY KEY (`id`, `restaurant_id`, `table_area_id`, `table_position_id`) COMMENT '',
46 UNIQUE INDEX `id_UNIQUE` (`id` ASC) COMMENT '',
47 INDEX `fk_restaurant_tables_restaurants_idx` (`restaurant_id` ASC) COMMENT '',
48 INDEX `fk_restaurant_tables_table_area1_idx` (`table_area_id` ASC) COMMENT '',
49 INDEX `fk_restaurant_tables_table_position1_idx` (`table_position_id` ASC) COMMENT '',
50 CONSTRAINT `fk_restaurant_tables_restaurants`
51 FOREIGN KEY (`restaurant_id`)
52 REFERENCES `projectx`.`restaurants` (`restaurant_id`)
53 ON DELETE NO ACTION
54 ON UPDATE NO ACTION,
55 CONSTRAINT `fk_restaurant_tables_table_area1`
56 FOREIGN KEY (`table_area_id`)
57 REFERENCES `projectx`.`table_area` (`area_id`)
58 ON DELETE NO ACTION
59 ON UPDATE NO ACTION,
60 CONSTRAINT `fk_restaurant_tables_table_position1`
61 FOREIGN KEY (`table_position_id`)
62 REFERENCES `projectx`.`table_position` (`position_id`)
63 ON DELETE NO ACTION
64 ON UPDATE NO ACTION)
65ENGINE = InnoDB;
66
67insert into restaurant_tables(id,table_id,restaurant_id,table_kind,number_of_seats,is_taken,table_area_id,table_position_id) values
68 (1,1,1,'square',4,0,1,1);