database
Author: NTHU CS 109062264 楊子慶
Course: CS471000 Introduction to Database Systems
Instructor: Shan-Hung Wu
Scenario
Let's say we want to design a database to manage the relationships between projects, professors, and students.
Question
CREATE TABLE
to present your schema.identify primary keys and foreign keys relationships
in your SQLs.the 3rd normal form
.Notice that
forum_name | popularity | post_id | title | article | reply |
---|---|---|---|---|---|
Gossiping | 100 | 131 | Girlfriend | How can I get girlfriend ? | ["Haha", "I don't know"] |
Gossiping | 100 | 252 | Firends | I don't have a friend… | ["Haha", "I can be", "QQ"] |
Joke | 23 | 46 | Knock | Knock! Knock! … | ["Then?", "What's the point ?"] |
Joke | 23 | 151 | Santa Claus | Hold! Hold! Hold! | ["XDD"] |
Here are its functional dependencies:
Please decompose the table to make it follow the 3rd normal form and identify which field(s) should be primary key(s). You must also keep the data in the table. You may add new fields to preserve the above relationships. (40 points)
Underlined attributes are primary keys.
forum information table
forum_name | popularity |
---|---|
Gossiping | 100 |
Joke | 23 |
Article table (article_id -> { forum_name, post_id }
)
article_id | forum_name | post_id | title | article |
---|---|---|---|---|
0 | Gossiping | 131 | Girlfriend | How can I get girlfriend ? |
1 | Gossiping | 252 | Firends | I don't have a friend… |
2 | Joke | 46 | Knock | Knock! Knock! … |
3 | Joke | 151 | Santa Claus | Hold! Hold! Hold! |
Reply table
Since number of replies is unfixed for each articles, I split the reply message into a new table.
reply_id | article_id | reply |
---|---|---|
0 | 0 | "Haha" |
1 | 0 | "I don't know" |
2 | 1 | "Haha" |
3 | 1 | "I can be" |
4 | 1 | "QQ" |
5 | 2 | "Then?" |
6 | 2 | "What's the point ?" |
7 | 3 | "XDD" |