数据库系统(五)——数据库设计

  1. 一、实验目的:
  2. 二、实验内容:
  3. 三、题目:Newspaper DataBase Design
  4. 四、ER图:
  5. 五、数据库实体关系设计:
  6. 六、实验小结:

一、实验目的:

  1. 熟悉数据库设计基本步骤;

  2. 练习数据库需求分析方法,并能给出数据字典;

  3. 练习 ER 图建模,掌握 ER 模型向关系模式的转化。

二、实验内容:

  1. 从用户需求出发,按照数据库设计步骤,分别完成如下内容:概念结构设计(ER 模型),给出满足需求的最终全局 ER 图,要求模型尽量精简,消除不必要的冗余,并给出理由或说明;

  2. 逻辑结构设计(关系模式),把 ER 模型转换成适当的关系模式,并进行适当地规范化,设计相关完整性约束。

三、题目:Newspaper DataBase Design

Newspaper System
报纸系统

A newspaper is setting up a website where people can write, read and comment on news stories. Your job is to design a database that can record the information needed for the website to work.
一家报纸正在建立一个网站,人们可以在那里撰写、阅读和评论新闻报道。你的工作是设计一个数据库,可以记录网站工作所需的信息。

The website lists a number of stories, each classified within one of about 10 sections (‘Local news’, ‘World news’,‘Opinion’, ‘Sport’, ‘Technology’ etc).
该网站列出了许多故事,每一个故事都被归入10个栏目(“本地新闻”、“世界新闻”、“观点”、“体育”、“科技”等)中的一个栏目里。

Each content of each story consists of a piece of text (the manager would prefer there to be no limit on the size) as well as a headline and a short “lede” (a lede is a sentence of 10 to 20 words that summarizes the story).
每个故事的每一个内容都由一段文字(经理希望没有大小限制)以及一个标题和一个简短的 “lede”(lede是一个10到20个单词的句子,用来总结故事)。

Each story is written by one or more of our authors, who submit the story to our database on a particular date.
每个故事都是由我们的一个或多个作者撰写的,他们在特定日期将故事提交到我们的数据库。

If a story is considered worthy, it is edited by one of our editors, assigned to a section, and then published on a particular date.
如果一个故事被认为是有价值的,它将由我们的一位编辑编辑,分配到一个部分,然后在一个特定的日期出版。

Authors and editors are staff members.
作者和编辑都是工作人员。

It is not possible to be both an author and an editor.
既当作家又当编辑是不可能的。

About each staff member we store their name and when they join (and later leave) the newspaper.
关于每一位员工,我们会保存他们的名字,以及他们何时加入(后来离开)报纸。

We want to organize the website so that readers can click on a section, or an author’s name, and see a list of all the relevant stories.
我们希望组织网站,这样读者可以点击某个部分或作者的名字,并看到所有相关故事的列表。

On the main page we list each story’s title (shown as a headline) and lede.
在主页上,我们列出每个故事的标题(作为标题显示)和lede。

Then if the reader clicks on the headline, we display the entire story.
然后,如果读者点击标题,我们就会显示整个故事。

Our readers, if they wish, can choose to register themselves in our database, recording a username and password (they do not need to record their real name).
我们的读者,如果他们愿意,可以选择在我们的数据库中注册,记录用户名和密码(他们不需要记录他们的真实姓名)。

Readers who register can then comment on stories, and on other readers’ comments.
注册的读者可以对故事和其他读者的评论进行评论。

They can also click “Like” on a story – and if they change their mind later, they can “Unlike” it.
他们还可以点击某个故事的“喜欢”按钮——如果他们后来改变了主意,他们可以“不喜欢”这个故事。

When we display a story we show the number of Likes the story has received and list out the comments below it.
当我们显示一个故事时,我们会显示这个故事收到的赞数,并在下面列出评论。

With each comment we show the username of the person who commented, and the time they commented.
在每条评论中,我们都会显示评论人的用户名以及他们评论的时间。

We aim for brevity in comments, and restrict them to 1024 characters.
我们的目标是在评论中保持简洁,限制在1024个字符以内。

四、ER图:

根据题意,画出 ER图:
在这里插入图片描述

其中关系模式如下:

  • 员工(姓名,加入日期,离开日期)
  • 新闻(标题,文本,简介)
  • 读者(用户名,密码)
  • 提交(提交日期,员工姓名,新闻)
  • 分类(栏目,新闻)
  • 评论(评论时间,新闻,读者用户名)
  • 评论评论(评论时间,评论,读者用户名)
  • 点赞(新闻,读者)

每个关系模式的主码、外码如下:

  • 员工(主码是姓名,无外码)
  • 新闻(主码是标题和文本,无外码)
  • 读者(主码是用户名,无外码)
  • 提交(主码是员工的姓名和新闻,外码是员工的姓名)
  • 分类(主码是栏目和新闻,无外码)
  • 评论(主码是新闻和读者用户名,外码是读者用户名)
  • 评论评论(主码是评论和读者用户名,外码是读者用户名)
  • 点赞(主码是新闻和读者用户名,外码是读者用户名)

五、数据库实体关系设计:

create table staff
(
Name varchar(10) primary key,
Join_date date,
Leave_date date
);

create table story
(
Headline VARCHAR(10),
Text varchar(100),
Lede varchar(50),
primary key(Headline,Text)
);

create table reader
(
Username varchar(20) primary key,
Password varchar(20)
);


create table submit
(
Submit_date date,
Name VARCHAR(5),
Headline VARCHAR(10),
primary key (Name,Headline),
foreign key (Name) references staff(Name)
);

create table class
(
Section varchar(5),
Headline VARCHAR(10),
primary key (Section,Headline)
);

create table comment
(
Comtime date,
Headline VARCHAR(10),
Name varchar(10),
primary key (Headline,Name),
foreign key(Name) references staff(Name)
);

create table comment_comment
(
Comtime date,
Comment varchar(50),
Name varchar(10),
primary key (Comment,Name),
foreign key(Name) references staff(Name)
);

create table praise
(
Headline VARCHAR(10),
Name varchar(10),
primary key (Headline,Name),
foreign key(Name) references staff(Name)
);

设计好的数据库模型如下:

在这里插入图片描述

六、实验小结:

应用数据库设计的范式理论对初始关系模型进行优化。数据库设计的三大范式如下:

  • 第一范式:每一个分类必须是一个不可分的数据项。属性不可再分,确保每列的原子性。

  • 第二范式:要求每个表只描述一件事情,每条记录有唯一标识列。

  • 第三范式:数据库表中不包含已在其它表中已包含的非主关键字信息。

参考文章:https://blog.csdn.net/COCO56/article/details/103470262


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 2058751973@qq.com

×

喜欢就点赞,疼爱就打赏