本文主要对某年代澳大利亚
某线上酒店预订网站进行数据库建模,相关的业务文档:
https://download.csdn.net/download/qq_33559972/10366961
上一步的用例建模工作参考我上一篇博客,上面开头把澳大利亚写成了意大利,特此更正:
https://blog.csdn.net/qq_33559972/article/details/80044209
Task 2 制图要求:
1.识别系统中的类及其属性,给出各个类之间的联系
2.识别类中的entity和mediator,并对应地将类的命名冠以字母E/M
E 一般与数据库构建有关,M 一般与store/session模式有关
设计说明:
Task 3 制图要求:
1.只转化实体类和他们之间的关系
2.用自动工具将图转化成关系数据库模式
MySQL Workbench下载链接:https://dev.mysql.com/downloads/workbench/
使用教程:https://blog.csdn.net/xujiayin/article/details/51689749
设计说明:
导出 Mysql 物理数据库的脚本:
-- MySQL Script generated by MySQL Workbench
-- Sun Apr 29 23:52:55 2018
-- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 ;
USE `mydb` ;
-- -----------------------------------------------------
-- Table `mydb`.`room_desc`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`room_desc` (
`type` VARCHAR(50) NOT NULL,
`list_price` FLOAT NOT NULL,
PRIMARY KEY (`type`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`availiable_date`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`availiable_date` (
`date` SMALLINT(30) NOT NULL,
`isAvailiable` TINYINT NULL DEFAULT 1,
PRIMARY KEY (`date`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`location`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`location` (
`code` INT NOT NULL,
`name` VARCHAR(10) NULL,
`hot` SMALLINT(5) NULL,
`type` SMALLINT(3) NULL,
`isCapital` TINYINT NULL DEFAULT 0,
PRIMARY KEY (`code`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`hotel`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`hotel` (
`name` VARCHAR(50) NOT NULL,
`intro` TEXT(100) NULL,
`star_index` SMALLINT(5) NULL,
`hot_index` SMALLINT(5) NULL,
`address` TEXT(80) NULL,
`location_code` INT NOT NULL,
PRIMARY KEY (`name`, `location_code`),
INDEX `fk_hotel_location1_idx` (`location_code` ASC),
CONSTRAINT `fk_hotel_location1`
FOREIGN KEY (`location_code`)
REFERENCES `mydb`.`location` (`code`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`room`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`room` (
`number` MEDIUMINT NOT NULL,
`room_desc_type` VARCHAR(50) NOT NULL,
`availiable_date_date` SMALLINT(30) NOT NULL,
`hotel_name` VARCHAR(50) NOT NULL,
PRIMARY KEY (`number`, `room_desc_type`, `availiable_date_date`, `hotel_name`),
INDEX `fk_room_room_desc_idx` (`room_desc_type` ASC),
INDEX `fk_room_availiable_date1_idx` (`availiable_date_date` ASC),
INDEX `fk_room_hotel1_idx` (`hotel_name` ASC),
CONSTRAINT `fk_room_room_desc`
FOREIGN KEY (`room_desc_type`)
REFERENCES `mydb`.`room_desc` (`type`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_room_availiable_date1`
FOREIGN KEY (`availiable_date_date`)
REFERENCES `mydb`.`availiable_date` (`date`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_room_hotel1`
FOREIGN KEY (`hotel_name`)
REFERENCES `mydb`.`hotel` (`name`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`reservation`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`reservation` (
`id` INT NOT NULL,
`total` FLOAT NULL,
`check_in` DATE NULL,
`check_out` DATE NULL,
`customer_name` VARCHAR(45) NULL,
`customer_email` VARCHAR(45) NULL,
`customer_sex` TINYINT NULL,
`customer_is_smoke` TINYINT NULL,
`customer_special_requirement` VARCHAR(45) NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`oder_item`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`oder_item` (
`number_of_adults` INT NULL,
`number_of_children` INT NULL,
`age_of_children` INT NULL,
`room_number` MEDIUMINT NOT NULL,
`room_room_desc_type` VARCHAR(50) NOT NULL,
`room_availiable_date_date` SMALLINT(30) NOT NULL,
`room_hotel_name` VARCHAR(50) NOT NULL,
`reservation_id` INT NOT NULL,
PRIMARY KEY (`room_number`, `room_room_desc_type`, `room_availiable_date_date`, `room_hotel_name`, `reservation_id`),
INDEX `fk_oder_item_room1_idx` (`room_number` ASC, `room_room_desc_type` ASC, `room_availiable_date_date` ASC, `room_hotel_name` ASC),
INDEX `fk_oder_item_reservation1_idx` (`reservation_id` ASC),
CONSTRAINT `fk_oder_item_room1`
FOREIGN KEY (`room_number` , `room_room_desc_type` , `room_availiable_date_date` , `room_hotel_name`)
REFERENCES `mydb`.`room` (`number` , `room_desc_type` , `availiable_date_date` , `hotel_name`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_oder_item_reservation1`
FOREIGN KEY (`reservation_id`)
REFERENCES `mydb`.`reservation` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
数据库逻辑模型与领域模型的异同:
一、相同:
二、不同: