Asg Task2
E-R模型
// 数据库脚本
-- MySQL Script generated by MySQL Workbench
-- Sat Apr 28 21:44:02 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`.`Search Option`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Search Option` (
`city` VARCHAR(256) NOT NULL,
`Checkin` DATE NOT NULL,
`Checkout` DATE NOT NULL,
`id` INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`ShopList`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`ShopList` (
`id` INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`Customer`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Customer` (
`Eamil` VARCHAR(256) NOT NULL,
`Search Option_city` VARCHAR(256) NOT NULL,
`ShopList_id` INT NOT NULL,
PRIMARY KEY (`Search Option_city`, `ShopList_id`),
INDEX `fk_Customer_ShopList1_idx` (`ShopList_id` ASC),
CONSTRAINT `fk_Customer_Search Option`
FOREIGN KEY (`Search Option_city`)
REFERENCES `mydb`.`Search Option` (`city`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Customer_ShopList1`
FOREIGN KEY (`ShopList_id`)
REFERENCES `mydb`.`ShopList` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
-- -----------------------------------------------------
-- Table `mydb`.`Hotel`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Hotel` (
`Name` VARCHAR(256) NOT NULL,
`LocatedCity` VARCHAR(45) NOT NULL,
`Search Option_id` INT NOT NULL,
`Customer_Search Option_city` VARCHAR(256) NOT NULL,
PRIMARY KEY (`Name`, `Search Option_id`, `Customer_Search Option_city`),
INDEX `fk_Hotel_Search Option1_idx` (`Search Option_id` ASC),
INDEX `fk_Hotel_Customer1_idx` (`Customer_Search Option_city` ASC),
CONSTRAINT `fk_Hotel_Search Option1`
FOREIGN KEY (`Search Option_id`)
REFERENCES `mydb`.`Search Option` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Hotel_Customer1`
FOREIGN KEY (`Customer_Search Option_city`)
REFERENCES `mydb`.`Customer` (`Search Option_city`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`Room`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Room` (
`Type` INT NOT NULL,
`Price` DOUBLE NOT NULL,
`Hotel_Name` VARCHAR(256) NOT NULL,
`Hotel_Search Option_id` INT NOT NULL,
`Hotel_Customer_Search Option_city` VARCHAR(256) NOT NULL,
PRIMARY KEY (`Type`, `Hotel_Name`, `Hotel_Search Option_id`, `Hotel_Customer_Search Option_city`),
INDEX `fk_Room_Hotel1_idx` (`Hotel_Name` ASC, `Hotel_Search Option_id` ASC, `Hotel_Customer_Search Option_city` ASC),
CONSTRAINT `fk_Room_Hotel1`
FOREIGN KEY (`Hotel_Name` , `Hotel_Search Option_id` , `Hotel_Customer_Search Option_city`)
REFERENCES `mydb`.`Hotel` (`Name` , `Search Option_id` , `Customer_Search Option_city`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`Payment`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Payment` (
`totalCost` DOUBLE NOT NULL,
`id` INT NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`Reservation`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Reservation` (
`details` VARCHAR(256) NOT NULL,
`total` INT NOT NULL,
`id` INT NOT NULL AUTO_INCREMENT,
`Payment_id` INT NOT NULL,
`ShopList_id` INT NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_Reservation_Payment1_idx` (`Payment_id` ASC),
INDEX `fk_Reservation_ShopList1_idx` (`ShopList_id` ASC),
CONSTRAINT `fk_Reservation_Payment1`
FOREIGN KEY (`Payment_id`)
REFERENCES `mydb`.`Payment` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Reservation_ShopList1`
FOREIGN KEY (`ShopList_id`)
REFERENCES `mydb`.`ShopList` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`CreditCard`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`CreditCard` (
`CardNumber` VARCHAR(256) NOT NULL,
`CardHolderAddress` VARCHAR(256) NOT NULL,
`Payment_id` INT NOT NULL,
PRIMARY KEY (`CardNumber`),
INDEX `fk_CreditCard_Payment1_idx` (`Payment_id` ASC),
CONSTRAINT `fk_CreditCard_Payment1`
FOREIGN KEY (`Payment_id`)
REFERENCES `mydb`.`Payment` (`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;
简单叙说 数据库逻辑模型 与 领域模型 的异同
数据模型是系统设计,以及实现的一部分,描述的是对用户需求在技术上的实现方法。用户不需要关心系统的数据模型,但是必须关注领域模型,因为领域模型反映的是问题域的相关业务概念以及其关系,领域模型是用户业务描述的高度抽象,来源于业务需求的描述,同时又可以帮助用户和需求分析人员更好的理解业务需求。数据库逻辑模型每个实体的属性都需要加上类型,比如int,float等,而领域模型不需要。数据库逻辑模型每个实体的属性具有主键,外键约束条件等关系,比领域模型更加复杂。