Question
The social media app you are designing a database for allows Users to share two kinds of content: **Messages** and **Stories**. Tables structure Decide what
The social media app you are designing a database for allows Users to share two kinds of content: **Messages** and **Stories**.
Tables structure
Decide what fields and data types are necessary for the two tables necessary for this app: `users` and `posts`. The `posts` table stores both Messages and Stories.
Bear in mind that the application must be able to use these tables to perform the required functionality outlined below.
Users:
Users can register for the app by supplying their...
- password
- handle (i.e. username).
Messages:
- Messages consist of text only.
- Messages are sent from one user to another specific user.
- Messages become invisible immediately after view and don't show up in the app thereafter.
- Messages are never actually deleted from the database table, even when invisible to the user (the social media company that produces the app keeps 'deleted' content in its database for future data harvesting, monetization purposes, and more.)
Stories:
- Stories consist of text only.
- Stories are public and every user can see them.
- Stories become invisible 24 hours after posting and don't show up in the app thereafter.
- Stories are never deleted from the database table, even when invisible to the user.
Write the SQL command to create these tables with the structure you determine is necessary.
### Practice data
Insert realistic-looking dummy data for one thousand Users, one thousand Messages, and one thousand Stories.
Include the practice data in CSV files named `users.csv` and `posts.csv` in the directory named `data`.
Write the SQLite commands necessary to import the data into the respective tables.
### Queries
Write a single SQL query to perform each of the followin tasks:
1. Register a new User.
1. Create a new Message sent by a particular User to a particular User (pick any two Users for example).
1. Create a new Story by a particular User (pick any User for example).
1. Show the 10 most recent visible Messages and Stories, in order of recency.
1. Show the 10 most recent visible Messages sent by a particular User to a particular User (pick any two Users for example), in order of recency.
1. Make all Stories that are more than 24 hours old invisible.
1. Show all invisible Messages and Stories, in order of recency.
1. Show the number of posts by each User.
1. Show the post text and email address of all posts and the User who made them within the last 24 hours.
1. Show the email addresses of all Users who have not posted anything yet.
### Hint
The following SQLite code returns the difference in hours between the time now and an earlier date and time - this may be useful in determining the number of hours that have passed since a post was made: `ROUND((JULIANDAY('now') - JULIANDAY('2021-02-21 12:50:00')) * 24)`
To see the return value of this command directly (not as part of a comparison operation), use the following syntax: `SELECT ROUND((JULIANDAY('now') - JULIANDAY('2021-02-21 12:50:00')) * 24);`
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started