Professional Documents
Culture Documents
Project Report
Project Report
Project Report
Normalization is the process of organizing and structuring Using Enumerated Data Types:
a relational database to reduce data redundancy and im- The use of ENUM types for attributes like gender,
prove data integrity. The main normalization procedures category, message_type, device_type, and privacy
typically involve breaking down tables and relationships to helps in maintaining data integrity and readability.
eliminate redundancy and dependency issues.
Normalization of Repeated Data:
First Normal Form (1NF): Separation of Concerns:
Elimination of Duplicate Columns: Authentication details are separated into the user_auth ta-
ble, ensuring that authentication-related information is
Each column in every table holds atomic (indivisi- stored independently.
ble) values.
VIEWS This view presents information about trending
posts based on like and comment counts.
A view is a virtual table that is based on the result of a SE- It uses LEFT JOINs to capture posts even if they
LECT query. It does not store the data itself but provides a have no likes or comments.
way to represent the data stored in one or more tables. The results are grouped by post and ordered by
Views can simplify complex queries, restrict access to spe- like count and comment count in descending or-
cific columns, or aggregate data. der.
1. Activity: 3. Followers:
Code: Code:
CREATE VIEW activity AS CREATE VIEW followers_view AS
SELECT SELECT
u.user_id, u.user_id AS follower_id,
u.user_name, u.user_name AS follower_user_name,
p.post_id, f.time_stamp,
p.post_content, u2.user_id AS following_id,
p.created_at AS post_created_at, u2.user_name AS following_user_name
c.comment_id, FROM followers f
c.comment_content, JOIN user_auth u ON f.follower_user_id = u.user_id
c.created_at AS comment_created_at, JOIN user_auth u2 ON f.following_user_id =
l.like_id, u2.user_id;
l.created_at AS like_created_at Explanation:
FROM user_auth u This view provides a clear representation of fol-
LEFT JOIN posts p ON u.user_id = p.author lowers and their corresponding following relation-
LEFT JOIN comments c ON u.user_id = c.user_id
ships.
LEFT JOIN likes l ON u.user_id = l.user_id;
It uses INNER JOINs to link follower and follow-
ing user details.
Explanation:
It uses INNER JOINs to link report details with 2. CREATING A POST:
information about the users who reported and Code:
were reported. DELIMITER $$
CREATE PROCEDURE create_post(
STORED PROCEDURES IN author_id CHAR(36),
IN post_content VARCHAR(255),
IN caption VARCHAR(255),
A stored procedure is a set of SQL statements that can be
IN location VARCHAR(255)
stored in a database and executed later. It allows for encap-
)
sulating a series of operations into a single named unit,
BEGIN
making code more modular and reusable. Stored proce-
DECLARE new_post_id CHAR(36);
dures can accept parameters, perform actions, and return
results.
INSERT INTO posts (post_id, post_content,
created_at, author, caption, location)
1. DELETING REPORTED USER (includes a trigger): VALUES (UUID(), post_content, NOW(), author_id,
Code: caption, location);
CREATE PROCEDURE delete_reported_user( in reported_profile_id
char(36) )
BEGIN SET new_post_id = LAST_INSERT_ID();
DECLARE total_reports int;
select count(*) SELECT new_post_id AS post_id;
INTO total_reports END
FROM report $$ DELIMITER ;
WHERE reported_profile = reported_profile_id;
CREATE PROCEDURE get_posts( Purpose: Retrieves the count of photo messages sent by a
IN user_id CHAR(36) user on a specific date.
) Parameters: userID, createdAt (date).
BEGIN Returns: The count of photo messages sent on the speci-
SELECT * fied date.
FROM posts
WHERE author = user_id; 2. LATEST POST:
Code:
END $$ DELIMITER $$CREATE FUNCTION
get_latest_post( user_id char(36) )
DELIMITER; returns char(36) reads sql data
BEGINDECLARE latest_post_id CHAR(36);SE-
Purpose: Retrieves all posts by a specific user. LECT post_id
Parameters: INTO latest_post_id
user_id: ID of the user whose posts are retrieved. FROM posts
Actions: WHERE author = user_id
Selects all posts from the posts table where the author ID ORDER BY created_at DESC limit 1;RETURN lat-
matches the provided user ID. est_post_id;END
$$ delimiter ;
FUNCTIONS
Request body:
{
In summary, the application utilizes a relational database
with multiple tables to store various types of data. Data re-
"table_name": "user",
trieval is achieved through SQL queries, often involving
"user_id": "21a8bd86-7561-4a8c- joins to assemble comprehensive information for display in
99be-6e094450f24c" the application's user interface. The database design sup-
} ports the features of the application and ensures efficient
data storage and retrieval.
According to the chart, 18–24 is the age group with the The pie chart shows that text posts are the most popular
most posts, followed by 25–34. 65 and older is the age type of post on social media, accounting for nearly half of
group with the fewest posts. With the exception of the 45– all posts. Image posts are also popular, accounting for 30%
54 age range, men posted more than women overall. of all posts. Video posts are less popular, accounting for
20% of all posts. Link posts are the least popular type of
Here is a more detailed breakdown of the chart: post, accounting for only 5% of all posts.
Age group 18-24: Males made 390 posts, while females
made 320 posts. This is likely because text posts are the easiest type of post
Age group 25-34: Males made 350 posts, while females to create. They also require the least amount of data to up-
made 280 posts. load, which is important for users who are on limited data
Age group 35-44: Males made 300 posts, while females plans. Image posts are also popular because they are vis-
made 260 posts. ually appealing and can be used to convey a lot of informa-
Age group 45-54: Males made 250 posts, while females tion quickly. Video posts can be even more engaging than
made 270 posts. image posts, but they can be more time-consuming to cre-
Age group 55-64: Males made 200 posts, while females ate and upload. Link posts are the least popular type of post
made 180 posts. because they are the least engaging. They also require
Age group 65+: Males made 150 posts, while females users to leave the social media platform in order to access
made 130 posts. the linked content.
Overall, the chart shows that younger users are more active Overall, the pie chart shows that text and image posts are
on social media than older users. It also shows that males the most popular types of posts on social media. Video
are more active on social media than females, except for in posts are less popular, but they are becoming more popular
the 45-54 age group. as internet speeds increase and social media platforms
make it easier to upload and share videos. Link posts are
the least popular type of post.