Vous êtes sur la page 1sur 11

CI6205 Database Systems

Assignment I

1. ER Diagram
Due to limited space, this report divides the ER Diagram into three groups. Group 1 (as
shown in figure 1) contains entity set Users, Groups, Pages, Posts, and Comments.
Additional assumptions:
1. An e-mail is used as an entity key to uniquely identify each entity of Users.
2. Entity set Groups, Posts, Pages, and Comments have a unique attribute called
Group_id, Post_id, Page_id, and Comment_id respectively, as their entity key.
3. Attribute content in entity set Posts contains some text and/or a photo. If a posts
content is associated with a photo, then the content will only store a link to the photo
file. Thus, in the implementation, the SNW application will use the link to show the
photo.
4. Attribute timestamp in entity set Posts and Comments is added to mark the time and
date of each record.

Figure 1. ER Diagram of Group 1

Group 2 (as shown in figure 2) contains entity set Users, Albums, and Photos. It also
contains roles of Users.
Additional assumptions:
1.
2.
3.
4.

Each entity in entity set Photos is identified by a unique filename.


Attribute caption in entity set Photos is added to store a brief description of the photo.
A unique attribute called Album_id is used as an entity key of entity set Albums.
Attribute timestamp in relation message is added to mark the time and date of each
record.

Figure 2. ER Diagram of Group 2

Group 3 (as shown in figure 3) contains entity set Users, Types, Ads, and Companies.
Additional assumptions:
1. Each entity in entity set Ads is uniquely identified by an attribute of product name
called Name.
2. Each entity in entity set Companies is uniquely identified by an attribute of company
name called Name.
3. Each entity in entity set Types is uniquely identified by an attribute called Type.

Figure 3. ER Diagram of Group 3


2. ER Diagram to Table Conversion
Group 1 conversion
These are the list of table conversions for group 1:
1. Tables from relation of Users, Groups, and Pages:
Users (E-mail, Name, Nationality, DoB, Page_id)
Groups (Group_id, Name, E-mail)
Member-of (Group_id, E-mail)
Pages (Page_id, Permission)
2. Tables from relation of Users, Posts, and Pages:
Posts (Post_id, Timestamp, Content, Visibility, E-mail, Page_id)
Like-a-post (E-mail, Post_id)
3. Tables from relation of Users, Comments, and Posts:
Comments (Comment_id, Timestamp, Text, E-mail, Post_id)
Like-a-comment (E_mail, Comment_id)
Group 2 conversion
Entity set Users is already translated into table in Group 1 conversion section. Therefore,
the remaining table conversions for this group are:
1. Tables from relation of Users, Albums, and Photos:
Albums (Album_id, Name, Visibility, E-mail)
Photos (Filename, Caption, Album_id)
2. Tables from role of Users:
Befriend (User, Friend)

Message (Sender, Recipient, Content, Timestamp)


Invite (Sender, Recipient, Type, Respond)

Group 3 conversion
Entity set Users is already translated into table in Group 1 conversion section. Therefore,
the remaining table conversions for this group are:
1. Tables from relation of Users and Types
Types (Type, Description)
Prefer (E-mail, Type)
2. Tables from relation of Users, Companies, Ads, and Types
Companies (Name, Address)
Ads (Name, Description, Fee, Start_date, End_date, Company_name)
Click (E-mail, Name, Date)
3. Functional Dependencies
These are the list of functional dependencies for each table schema:
1. Table Users (E-mail, Name, Nationality, DoB, Page_id)
E-mail Name, Nationality, DoB; E-mail Page_id
2. Table Groups (Group_id, Name, E-mail)
Group_id Name; Group_id E-mail
3. Table Member-of (Group_id, E-mail)
No functional dependency because all of the functional dependencies are trivial.
4. Table Pages (Page_id, Permission)
Page_id Permission
5. Table Posts (Post_id, Timestamp, Content, Visibility, E-mail, Page_id)
Post_id Timestamp, Content, Visibility; Post_id E-mail; Post_id Page_id
6. Table Like-a-post (E-mail, Post_id)
No functional dependency because all of the functional dependencies are trivial.
7. Table Comments (Comment_id, Timestamp, Text, E-mail, Post_id)
Comment_id Timestamp, Text; Comment_id E-mail; Comment_id Post_id
8. Table Like-a-comment (E_mail, Comment_id)
No functional dependency because all of the functional dependencies are trivial.
9. Table Albums (Album_id, Name, Visibility, E-mail)
Album_id Name, Visibility; Album_id E-mail
10. Table Photos (Filename, Caption, Album_id)
Filename Caption; Filename Album_id;

11. Table Befriend (User, Friend)


No functional dependency because all of the functional dependencies are trivial.
12. Table Message (Sender, Recipient, Content, Timestamp)
Sender, Recipient, Timestamp Content
13. Table Invite (Sender, Recipient, Type, Respond)
Sender, Recipient, Type Respond
14. Table Types (Type, Description)
Type Description
15. Table Prefer (E-mail, Type)
No functional dependency because all of the functional dependencies are trivial.
16. Table Companies (Name, Address)
Name Address
17. Table Ads (Name, Description, Type, Company_name, Fee, Start_date, End_date)
Name Description, Type; Name Company_name;
Name Fee, Start_date, End_date
18. Table Click (E-mail, Name, Date)
E-mail, Date Name; Name, Date E-mail
4. BCNF Check
Following are the identification of BCNF for each table:
1. Table Users (E-mail, Name, Nationality, DoB, Page_id)
E-mail Name, Nationality, DoB; E-mail Page_id
Based on the given functional dependencies, it can be derived that the key for table
Users is E-mail. This table satisfies the definition of BCNF table because for each
non-trivial functional dependency that is derived from the table, its left-hand side is a
superkey of table Users. This is achieved because every subset of attributes in the
table that contains more than one attribute always contains the key.
2. Table Groups (Group_id, Name, E-mail)
Group_id Name; Group_id E-mail
Based on the given functional dependencies, it can be derived that the key for table
Groups is Group_id. This table satisfies the definition of BCNF table because for each
non-trivial functional dependency that is derived from the table, its left-hand side is a
superkey of table Groups. This is achieved because every subset of attributes in the
table that contains more than one attribute always contains the key.
3. Table Member-of (Group_id, E-mail)
Table Member-of is already in BCNF because all of its functional dependencies are
trivial. Moreover, every table with only two attributes is a BCNF table.

4. Table Pages (Page_id, Permission)


Page_id Permission
Table Pages is already in BCNF because it has only two attributes.
5. Table Posts (Post_id, Timestamp, Content, Visibility, E-mail, Page_id)
Post_id Timestamp, Content, Visibility; Post_id E-mail; Post_id Page_id
Based on the given functional dependencies, it can be derived that the key for table
Posts is Post_id. This table satisfies the definition of BCNF table because for each
non-trivial functional dependency that is derived from the table, its left-hand side is a
superkey of table Posts. This is achieved because every subset of attributes in the
table that contains more than one attribute always contains the key.
6. Table Like-a-post (E-mail, Post_id)
Table Like-a-post is already in BCNF because all of its functional dependencies are
trivial. Moreover, every table with only two attributes is a BCNF table.
7. Table Comments (Comment_id, Timestamp, Text, E-mail, Post_id)
Comment_id Timestamp, Text; Comment_id E-mail; Comment_id Post_id
Based on the given functional dependencies, it can be derived that the key for table
Comments is Comment_id. This table satisfies the definition of BCNF table because
for each non-trivial functional dependency that is derived from the table, its left-hand
side is a superkey of table Comments. This is achieved because every subset of
attributes in the table that contains more than one attribute always contains the key.
8. Table Like-a-comment (E_mail, Comment_id)
Table Like-a-comment is already in BCNF because all of its functional dependencies
are trivial. Moreover, every table with only two attributes is a BCNF table.
9. Table Albums (Album_id, Name, Visibility, E-mail)
Album_id Name, Visibility; Album_id E-mail
Based on the given functional dependencies, it can be derived that the key for table
Albums is Album_id. This table satisfies the definition of BCNF table because for
each non-trivial functional dependency that is derived from the table, its left-hand side
is a superkey of table Albums. This is achieved because every subset of attributes in
the table that contains more than one attribute always contains the key.
10. Table Photos (Filename, Caption, Album_id)
Filename Caption; Filename Album_id
Based on the given functional dependencies, it can be derived that the key for table
Photos is Filename. This table satisfies the definition of BCNF table because for each
non-trivial functional dependency that is derived from the table, its left-hand side is a
superkey of table Photos. This is achieved because every subset of attributes in the
table that contains more than one attribute always contains the key.
11. Table Befriend (User, Friend)
Table Befriend is already in BCNF because all of its functional dependencies are
trivial. Moreover, every table with only two attributes is a BCNF table.
12. Table Message (Sender, Recipient, Content, Timestamp)
Sender, Recipient, Timestamp Content

Based on the given functional dependencies, it can be derived that the key for table
Message is {Sender, Recipient, Timestamp}. This table satisfies the definition of
BCNF table because other than the given functional dependencies, all of derived
functional dependencies are trivial.
13. Table Invite (Sender, Recipient, Type, Respond)
Sender, Recipient, Type Respond
Based on the given functional dependencies, it can be derived that the key for table
Message is {Sender, Recipient, Type}. This table satisfies the definition of BCNF
table because other than the given functional dependencies, all of derived functional
dependencies are trivial.
14. Table Types (Type, Description)
Type Description
Table Types is already in BCNF because it has only two attributes.
15. Table Prefer (E-mail, Type)
Table Prefer is already in BCNF because all of its functional dependencies are trivial.
Moreover, every table with only two attributes is a BCNF table.
16. Table Companies (Name, Address)
Name Address
Table Companies is already in BCNF because it has only two attributes.
17. Table Ads (Name, Description, Type, Company_name, Fee, Start_date, End_date)
Name Description, Type; Name Company_name;
Name Fee, Start_date, End_date
Based on the given functional dependencies, it can be derived that the key for table
Message is Name. This table satisfies the definition of BCNF table because for each
non-trivial functional dependency that is derived from the table, its left-hand side is a
superkey of table Ads. This is achieved because every subset of attributes in the table
that contains more than one attribute always contains the key.
18. Table Click (E-mail, Name, Date)
E-mail, Date Name; Name, Date E-mail
Based on the given functional dependencies, it can be derived that the keys for table
Click are {E-mail, Date} and {Name, Date}. This table satisfies the definition of
BCNF table because other than the given functional dependencies, all of derived
functional dependencies are trivial.
5. 3NF Check
Since from step 4 there is no table that has been decomposed, all of functional
dependencies in every BCNF table is still preserved. Therefore, there is no need to check
whether each table is in 3NF.

6. Final Table
Following are final tables that exist in the SNW:
1. Users table
Attribute

E-mail

Primary Key
Foreign Key
(FK)

Name

Nationality

DoB

Page_id

Pages
(Page_id)

FK Reference

2. Groups table
Attribute

Group_id

Primary Key
Foreign Key
(FK)
FK Reference

Name

E-mail

Users (E-mail)

3. Member-of table
Attribute

Group_id

E-mail

Primary Key
Foreign Key
(FK)

Groups
(Group_id)

Users
(E-mail)

Attribute

Page_id

Permission

Primary Key
Foreign Key
(FK)

FK Reference

4. Pages table

FK Reference

5. Posts table
Attribute

Post_id

Primary Key
Foreign Key
(FK)

FK Reference

Timestamp

Content

Visibility

E-mail

Page_id

Users
(E-mail)

Pages
(Page_id)

6. Like-a-post table
Attribute

E-mail

Post_id

Primary Key
Foreign Key
(FK)

Users
(E-mail)

Posts
(Post_id)

FK Reference

7. Comments table
Attribute
Primary Key
Foreign Key
(FK)

Comment_id Timestamp

Text

E-mail

Post_id

Users
(E-mail)

Posts
(Post_id)

FK Reference

8. Like-a-comment table
Attribute

E-mail

Comment_id

Primary Key
Foreign Key
(FK)

Users
(E-mail)

Comments
(Comment_id)

FK Reference

9. Albums table
Attribute

Album_id

Primary Key
Foreign Key
(FK)

Name

Visibility

Users
(E-mail)

FK Reference

10. Photos table


Attribute

Filename

Primary Key
Foreign Key
(FK)

FK Reference

E-mail

Caption

Album_id

Albums
(Album_id)

11. Befriend table


Attribute

User

Friend

Primary Key
Foreign Key
(FK)

Users
(E-mail)

Users
(E-mail)

Attribute

Sender

Recipient

Timestamp

Primary Key
Foreign Key
(FK)

Users
(E-mail)

Users
(E-mail)

Attribute

Sender

Recipient

Type

Primary Key
Foreign Key
(FK)

Users
(E-mail)

Users
(E-mail)

Attribute

Type

Description

Primary Key
Foreign Key
(FK)

FK Reference

12. Message table

FK Reference

Content

13. Invite table

FK Reference

14. Types table

FK Reference

15. Prefer table


Attribute

E-mail

Type

Primary Key
Foreign Key
(FK)

Users
(E-mail)

Types
(Type)

FK Reference

Respond

16. Companies table


Attribute

Name

Primary Key
Foreign Key
(FK)

Address

FK Reference

17. Ads table


Attribute
Primary
Key
Foreign
Key (FK)
FK
Reference

Name

Description

Fee

Start_date End_date Company_name

18. Click table


Attribute

E-mail

Name

Date

Primary Key
Foreign Key
(FK)

Users
(E-mail)

Ads
(Name)

FK Reference

Type

Companies
(Name)

Types
(Type)