Database system (5)-database design

1. The purpose of the experiment:

  1. Familiar with the basic steps of database design;

  2. Practice database requirements analysis methods, and be able to give a data dictionary;

  3. Practice ER diagram modeling and master the transformation of ER model to relational mode.

2. Experimental content:

  1. Starting from user needs and following the database design steps, complete the following: Conceptual structure design (ER model), give the final global ER diagram that meets the needs, require the model to be as streamlined as possible, eliminate unnecessary redundancy, and give reasons or Description

  2. Logical structure design (relational model), transform the ER model into an appropriate relational model, and properly standardize it, and design related integrity constraints.

3. Title: Newspaper DataBase Design

Newspaper System
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.
A newspaper is building a site where people can write in there , Read and comment on news reports. Your job is to design a database that can record the information needed for website work.

The website lists a number of stories, each classified within one of about 10 sections ( 'Local news', 'World news', 'Opinion', 'Sport', 'Technology' etc).
The site lists a number of stories, each A story is classified into one of 10 columns ("Local News", "World News", "Viewpoints", "Sports", "Technology", etc.).

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).
Each content of each story consists of a paragraph of text (the manager hopes that there is no size limit), a title and a short "lede" (lede is a sentence of 10 to 20 words used to summarize the story).

Each story is written by one or more of our authors, who submit the story to our database on a particular date.
Each story is one or more of our authors write, they will submit to us the story of a particular date database.

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.
If a story is considered to be valuable, it will be by our editor, an editor assigned to A section is then published on a specific date.

Authors and editors are staff members. Authors and editors are staff members
.

It is not possible to be both an author and an editor. 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.
We want to organize the site so that readers can click on a part or the author's name, and see A list of all related stories.

On the main page we list each story's title (shown as a headline) and lede. On the main page we list each story's title (shown as a headline
) and 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).
Our readers, if they wish, can choose to register in our database, Record the username and password (they don't 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. They can also click the “Like” button of a story – if they change their mind later, they can
“ I don’t like the story.

When we display a story we show the number of Likes the story has received and list out the comments below 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.
In each comment, we will show the user name of the commenter and the time they commented .

We aim for brevity in comments, and restrict them to 1024 characters.
Our goal is to keep the comments concise and limit them to 1024 characters .

Four, ER graphics:

According to the meaning of the question, draw the ER diagram:
Insert picture description here

The relationship model is as follows:

  • Employee (name, date of joining, date of leaving)
  • News (title, text, introduction)
  • Reader (username, password)
  • Submission (submission date, employee name, news)
  • Category (column, news)
  • Comments (comment time, news, reader username)
  • Comment comments (comment time, comment, reader username)
  • Likes (news, readers)

The main code and outer code of each relational model are as follows:

  • Employee (the main code is the name, no foreign code)
  • News (the main code is the title and text, no foreign code)
  • Reader (the main code is the user name, no foreign code)
  • Submit (the main code is the employee's name and news, and the foreign code is the employee's name)
  • Classification (the main code is column and news, no foreign code)
  • Comment (the main code is the user name of the news and readers, and the foreign code is the user name of the reader)
  • Comment comments (the main code is the comment and the reader's username, and the outer code is the reader's username)
  • Like (the main code is the user name of news and readers, and the outer code is the user name of readers)

5. Database entity relationship design:

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)
);

The designed database model is as follows:

Insert picture description here

6. Summary of the experiment:

The paradigm theory of database design is applied to optimize the initial relational model. The three paradigms of database design are as follows:

  • First paradigm: Each category must be an indivisible data item. The attributes cannot be divided to ensure the atomicity of each column.

  • The second paradigm: each table is required to describe only one thing, and each record has a unique identification column.

  • The third normal form: the database table does not contain non-primary key information that has been included in other tables.

Reference article: https://blog.csdn.net/COCO56/article/details/103470262

Guess you like

Origin blog.csdn.net/qq_43531669/article/details/111132260