Asg Task2
hw 4.pngER 模型
hw4_er.png-- MySQL Script generated by MySQL Workbench
-- Sun Apr 29 19:27:01 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`.`Customer`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Customer` (
`id` INT NOT NULL,
`name` VARCHAR(45) NULL,
`gender` TINYINT NULL,
`special_requirements` VARCHAR(45) NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `id_UNIQUE` (`id` ASC))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`Reservation`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Reservation` (
`id` INT NOT NULL,
`price` FLOAT NULL,
`date` DATE NULL,
`Customer_id` INT NOT NULL,
PRIMARY KEY (`id`, `Customer_id`),
UNIQUE INDEX `idreservation_UNIQUE` (`id` ASC),
INDEX `fk_Reservation_Customer1_idx` (`Customer_id` ASC),
CONSTRAINT `fk_Reservation_Customer1`
FOREIGN KEY (`Customer_id`)
REFERENCES `mydb`.`Customer` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`Credit_card`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Credit_card` (
`cardNumber` INT NOT NULL,
`Address` VARCHAR(45) NULL,
`Customer_id` INT NOT NULL,
PRIMARY KEY (`cardNumber`, `Customer_id`),
INDEX `fk_Credit_card_Customer1_idx` (`Customer_id` ASC),
CONSTRAINT `fk_Credit_card_Customer1`
FOREIGN KEY (`Customer_id`)
REFERENCES `mydb`.`Customer` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`Hotel`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Hotel` (
`id` INT NOT NULL,
`name` VARCHAR(45) NULL,
`city` VARCHAR(45) NULL,
`address` VARCHAR(45) NULL,
`star` INT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `id_UNIQUE` (`id` ASC))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`Room`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Room` (
`id` INT NOT NULL,
`roomType` VARCHAR(45) NULL,
`Hotel_id` INT NOT NULL,
`Reservation_id` INT NOT NULL,
`Reservation_Customer_id` INT NOT NULL,
PRIMARY KEY (`id`, `Hotel_id`, `Reservation_id`, `Reservation_Customer_id`),
UNIQUE INDEX `id_UNIQUE` (`id` ASC),
INDEX `fk_Room_Hotel1_idx` (`Hotel_id` ASC),
INDEX `fk_Room_Reservation1_idx` (`Reservation_id` ASC, `Reservation_Customer_id` ASC),
CONSTRAINT `fk_Room_Hotel1`
FOREIGN KEY (`Hotel_id`)
REFERENCES `mydb`.`Hotel` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Room_Reservation1`
FOREIGN KEY (`Reservation_id` , `Reservation_Customer_id`)
REFERENCES `mydb`.`Reservation` (`id` , `Customer_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;
简单叙述 数据库逻辑模型 与 领域模型 的异同
相同点
- 在“实体”的概念上有相似点,都描述了实体间的关系,每个实体有对应的属性
不同点
- 领域模型根据用例场景分析得到实体,而数据库逻辑模型式根据场景分析业务实体之间的关系,用户不需要关心系统的数据模型,但是必须关注领域模型
- 领域模型的实体并不是全部都需要存储下来的,而数据库逻辑的实体要受到数据关系范式的限制;
- 数据库逻辑模型以数据为中心,关注的是对象的实体和关系,建模时不考虑Entity的行为;而领域模型是属于对象建模的范畴,需要为对象建立行为。
- 数据库逻辑模型每个实体的属性都需要加上类型,比如int,float等,而领域模型不需要
网友评论