A database schema is a blueprint that defines the structure and organization of a database, including tables, columns, relationships, and constraints. Here is a simple example of a database schema for a basic social media platform:
- Users Table:
- user_id (Primary Key, Integer, Auto Increment)
- username (Text, Unique, Not Null)
- email (Text, Unique, Not Null)
- password (Text, Not Null)
- full_name (Text, Not Null)
- date_of_birth (Date)
- date_created (Datetime, Not Null)
- date_modified (Datetime)
- Posts Table:
- post_id (Primary Key, Integer, Auto Increment)
- user_id (Foreign Key, Integer, Not Null, References Users(user_id))
- content (Text, Not Null)
- image_url (Text)
- date_posted (Datetime, Not Null)
- date_modified (Datetime)
- Comments Table:
- comment_id (Primary Key, Integer, Auto Increment)
- post_id (Foreign Key, Integer, Not Null, References Posts(post_id))
- user_id (Foreign Key, Integer, Not Null, References Users(user_id))
- content (Text, Not Null)
- date_posted (Datetime, Not Null)
- date_modified (Datetime)
- Likes Table:
- like_id (Primary Key, Integer, Auto Increment)
- post_id (Foreign Key, Integer, Not Null, References Posts(post_id))
- user_id (Foreign Key, Integer, Not Null, References Users(user_id))
- date_liked (Datetime, Not Null)
- Followers Table:
- follower_id (Primary Key, Integer, Auto Increment)
- user_id (Foreign Key, Integer, Not Null, References Users(user_id))
- follower_user_id (Foreign Key, Integer, Not Null, References Users(user_id))
- date_followed (Datetime, Not Null)
This schema includes five tables: Users, Posts, Comments, Likes, and Followers. The schema outlines each table's columns, primary keys, foreign keys, and any other necessary constraints. This is just a simple example, and your database schema may need to be more complex based on your specific requirements.