SQL代写:CS420 Database Design

Introduction

Database design最简单的设计模型就是E-R模型,E-R建模工具有很多,最简单方便的当属Microsoft Office Visio
E-R模型图由实体Entities以及关系Relationship组成,其中实体Entities可能包含属性Properties/Attributes。E-R图反映了现实世界中的一些现象,如客户和书店、供销商和书店之间是供求关系,而客户、书店和供销商之间,各自又存在属性,如名称、电话等。
关系不一定是一对一,也可能是一对多、多对一、多对多关系,如一本书可以对应多个作者,而一名作者也可以对应多本书。这类情形也可以由E-R图反映。

Requirement

In this assignment, you are designing an online bookstore database. The storekeeper wants to record the publishers, books and buyer. For each publisher, the storekeeper records the email address, phone number and book genres. For each book the storekeeper records the ISBN, book title, authors and price. For each buyer the storekeeper records the name, phone number, and purchase amount in total.
Note that the storekeeper doesn’t want to record which book is bought by which buyer. You should to drow an E-R diagrams to demonstrate your database design.

Analysis

画E-R图之前,一定要分清楚到底什么是实体,以及实体之间的关系。有下面几个技巧需要注意:

  1. 同名的实体只出现一次,如book只用出现一次,不需要专门指出是什么类型的book
  2. 能实用属性的,就不要使用实体,如book的name是book的属性,不要把book和name设计为两个entity
  3. Relationship能省则省,这样才能简化模型,如book和name之间不是关系,而是name是book的属性

本题是根据场景设计E-R图,实体有3个,即Publisher、Book和Buyer。他们各自的属性如下:

  • Publisher: email address, phone number, book genres
  • Book: ISBN, book title, authors, price
  • Buyer: name, phone number, purchase amount in total

其中,Publisher和Book之间存在供应关系,Book和Buyer之间存在购买关系,因此关系有2个。
利用Visio可以很容易的画出本题所需的E-R图,进而完成Database design.