数据库系统(五)——数据库设计
文章目錄
- 一、實驗目的:
- 二、實驗內容:
- 三、題目:Newspaper DataBase Design
- 四、ER圖:
- 五、數據庫實體關系設計:
- 六、實驗小結:
一、實驗目的:
熟悉數據庫設計基本步驟;
練習數據庫需求分析方法,并能給出數據字典;
練習 ER 圖建模,掌握 ER 模型向關系模式的轉化。
二、實驗內容:
從用戶需求出發,按照數據庫設計步驟,分別完成如下內容:概念結構設計(ER 模型),給出滿足需求的最終全局 ER 圖,要求模型盡量精簡,消除不必要的冗余,并給出理由或說明;
邏輯結構設計(關系模式),把 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
總結
以上是生活随笔為你收集整理的数据库系统(五)——数据库设计的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java EE——Mybatis 框架学
- 下一篇: 数据库系统(一)——数据查询