系统分析与设计 Lesson 7 作业

1. 领域建模

a. 阅读Asg_RH文档,按用例构建领域模型

系统分析与设计 Lesson 7 作业_第1张图片
image.png

b. 数据库建模(E-R模型)

系统分析与设计 Lesson 7 作业_第2张图片
image.png

导出SQL

-- MySQL Script generated by MySQL Workbench
-- Sun Apr 29 08:46:12 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`.`Traveller`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Traveller` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `email` VARCHAR(45) NOT NULL,
  `password` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`CreditCard`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`CreditCard` (
  `creditcard_id` INT NOT NULL AUTO_INCREMENT,
  `traveller_id` INT NOT NULL,
  `card_number` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`creditcard_id`, `traveller_id`),
  INDEX `fk_CreditCard_Traveller1_idx` (`traveller_id` ASC),
  CONSTRAINT `fk_CreditCard_Traveller1`
    FOREIGN KEY (`traveller_id`)
    REFERENCES `mydb`.`Traveller` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Destination`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Destination` (
  `destination_id` INT NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`destination_id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Hotel`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Hotel` (
  `hotel_id` INT NOT NULL AUTO_INCREMENT,
  `destination_id` INT NOT NULL,
  `name` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`hotel_id`, `destination_id`),
  INDEX `fk_Hotel_Destination1_idx` (`destination_id` ASC),
  CONSTRAINT `fk_Hotel_Destination1`
    FOREIGN KEY (`destination_id`)
    REFERENCES `mydb`.`Destination` (`destination_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Room`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Room` (
  `room_id` INT NOT NULL AUTO_INCREMENT,
  `hotel_id` INT NOT NULL,
  `price` DOUBLE NOT NULL,
  PRIMARY KEY (`room_id`, `hotel_id`),
  INDEX `fk_Room_Hotel_idx` (`hotel_id` ASC),
  CONSTRAINT `fk_Room_Hotel`
    FOREIGN KEY (`hotel_id`)
    REFERENCES `mydb`.`Hotel` (`hotel_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Reservation`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Reservation` (
  `reservation_id` INT NOT NULL AUTO_INCREMENT,
  `room_id` INT NOT NULL,
  `hotel_id` INT NOT NULL,
  `creditcard_id` INT NOT NULL,
  `traveller_id` INT NOT NULL,
  `checkin_time` DATETIME NOT NULL,
  `checkout_time` DATETIME NOT NULL,
  `table1col` VARCHAR(45) NULL,
  PRIMARY KEY (`reservation_id`, `room_id`, `hotel_id`, `creditcard_id`, `traveller_id`),
  INDEX `fk_Reservation_Room1_idx` (`room_id` ASC, `hotel_id` ASC),
  INDEX `fk_Reservation_CreditCard1_idx` (`creditcard_id` ASC, `traveller_id` ASC),
  CONSTRAINT `fk_Reservation_Room1`
    FOREIGN KEY (`room_id` , `hotel_id`)
    REFERENCES `mydb`.`Room` (`room_id` , `hotel_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Reservation_CreditCard1`
    FOREIGN KEY (`creditcard_id` , `traveller_id`)
    REFERENCES `mydb`.`CreditCard` (`creditcard_id` , `traveller_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;

数据库逻辑模型 与 领域模型 的异同

  • 数据库逻辑模型每个实体的属性都考虑数据类型,而领域模型不需要
  • 数据库逻辑模型需要考虑实体之间的主键或外键关联,比领域模型只考虑一对一还是一对多的关系

你可能感兴趣的:(系统分析与设计 Lesson 7 作业)