Homework 1: Database Schema Design
The goal of this homework is to practice designing a database schema.
Instructions
You are welcome to work with a partner.
- Either use the website you analyzed in Lab 1, or choose another database application with which you are familiar.
- Design a schema and populate it with example data. Your schema should include:
- At least four tables. Use the notation shown in the example below.
- Each table should include at least four rows (records) of example data.
- List at least four database constraints which should constrain data stored by the schema.
- List three users of your database. For each user:
- In detail, describe what data should be visible to them.
- In detail, describe what data (if any) they should have permission to modify.
Hint: Section 1.6.8 describes examples of constraints you might include.
Example
- Database application: Facebook
- Schema: (See tables below)
- Contraints:
- Each
Email
in theUsers
table must be unique - Each
Email
in theUsers
table must be a valid email address - Each
ID
in theUsers
table must be unique - Each
Birthday
in theUsers
table must be a valid date - Each
User ID 1
andUser ID 2
in theFriendship
table must correspond to values in theUsers
table
- Each
- Users of the database:
- Personal users:
- Can view and edit all attributes of their record in the
Users
table - Can view the
Name
attribute of all records in theUsers
table - Can view all
Users
table attributes of all their friends - Can view and edit their own
Status Updates
- Can view all
Organizations
records - Can view and edit their own
Likes
- Can view and edit all attributes of their record in the
- Organizational users:
- Can view and edit all attributes of their record in the
Organizations
table - Can view the number of
Likes
for their organization
- Can view and edit all attributes of their record in the
- Facebook admins:
- Can view and edit all attributes of all tables
- Personal users:
Users
ID | Name | Password | Birthday | Phone Number | Relationship | |
---|---|---|---|---|---|---|
111 | Peter Story | PeStory@clarku.edu | — | Jan 1, 1990 | 111-222-3333 | Married |
112 | Abe Story | AbStory@clarku.edu | — | Feb 1, 1980 | 111-222-3334 | Single |
113 | Ben Story | BeStory@clarku.edu | — | Mar 1, 1970 | 111-222-3335 | Married |
114 | Cathy Story | CaStory@clarku.edu | — | Apr 1, 1960 | 111-222-3336 | Unknown |
Friendship
User ID 1 | User ID 2 |
---|---|
111 | 112 |
111 | 113 |
111 | 114 |
112 | 113 |
Status Updates
Timestamp | User ID | Text |
---|---|---|
2023-11-29 10:57:01 | 111 | The CMACD building is great! |
2023-11-29 11:38:17 | 111 | Why is it so cold outside? |
2023-11-29 11:46:29 | 112 | Looking forward to summer! |
2023-11-29 14:38:17 | 113 | I’m quitting social media! |
Organizations
Org ID | Name | Address |
---|---|---|
1111 | Facebook Boston | 100 Binney St Cambridge, MA 02142 |
2222 | Apple | 1 Infinite Loop Cupertino, CA 95014 |
3333 | Clark University | 950 Main St Worcester, MA 01610 |
4444 | Worcester DPW | 20 East Worcester St Worcester, MA 01604 |
Likes
User ID | Org ID |
---|---|
111 | 1111 |
112 | 2222 |
113 | 3333 |
113 | 4444 |
Submit
Upload a PDF with your responses.