Designing a Social Network Database Schema

This technical problem deals with designing a social network database schema that includes posts, comments, and likes. The input is a set of CREATE TABLE statements for the three tables, and the output is sample data for those tables.

Problem

Design a database schema for a social network that includes posts, comments, and likes.
Input:
CREATE TABLE posts (
  id INTEGER PRIMARY KEY,
  content TEXT,
  user_id INTEGER,
  FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE comments (
  id INTEGER PRIMARY KEY,
  content TEXT,
  post_id INTEGER,
  user_id INTEGER,
  FOREIGN KEY (post_id) REFERENCES posts(id),
  FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE likes (
  id INTEGER PRIMARY KEY,
  post_id INTEGER,
  user_id INTEGER,
  FOREIGN KEY (post_id) REFERENCES posts(id),
  FOREIGN KEY (user_id) REFERENCES users(id)
);
Output:
id | content | user_id
1  | Hello!  | 1 2  | Bye!    | 2
id | content | post_id | user_id
1  | Nice!   | 1       | 2
2  | Lol     | 2       | 1
id | post_id | user_id
1  | 1       | 2
2  | 2       | 1

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
/*

Solution:

The solution is optimal because it uses foreign keys to ensure data integrity.

*/

A.I. Evaluation of the Solution

The solution is optimal because it uses foreign keys to ensure data integrity.

Evaluated at: 2022-11-22 12:16:31