1. 領(lǐng)域建模
a. 閱讀Asg_RH文檔,按用例構(gòu)建領(lǐng)域模型
image.png
b. 數(shù)據(jù)庫建模(E-R模型)
image.png
導(dǎo)出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;
數(shù)據(jù)庫邏輯模型 與 領(lǐng)域模型 的異同
- 數(shù)據(jù)庫邏輯模型每個(gè)實(shí)體的屬性都考慮數(shù)據(jù)類型含长,而領(lǐng)域模型不需要
- 數(shù)據(jù)庫邏輯模型需要考慮實(shí)體之間的主鍵或外鍵關(guān)聯(lián)澄成,比領(lǐng)域模型只考慮一對(duì)一還是一對(duì)多的關(guān)系