DEV Community

Cover image for Basic Relational Database Schemas πŸ“š to amplify development
aryan015
aryan015

Posted on

Basic Relational Database Schemas πŸ“š to amplify development

Whether you are using either non-relational or relational DBMS the fundamental would be the same. It contents key-value pair which has some default value before assignment. Please save it for future reference πŸ˜‰.

Table: users

Column Name Data Type Constraints Description
user_id BIGINT UNSIGNED PRIMARY KEY, AUTO_INCREMENT Unique User ID
user_name VARCHAR(50) NOT NULL Full Name
user_email VARCHAR(100) NOT NULL, UNIQUE Email Address
password VARCHAR(255) NOT NULL Hashed Password
role ENUM('admin', 'user', 'editor') DEFAULT 'user' User Role
status TINYINT(1) DEFAULT 1 1 = Active, 0 = Inactive
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP Timestamp of creation
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP Last update timestamp

Table: posts

Column Name Data Type Constraints Description
post_id BIGINT UNSIGNED PRIMARY KEY, AUTO_INCREMENT Unique Post ID
user_id BIGINT UNSIGNED FOREIGN KEY -> users(user_id), NOT NULL Post Author ID
title VARCHAR(255) NOT NULL Post Title
content TEXT NOT NULL Post Content
status ENUM('draft', 'published', 'archived') DEFAULT 'draft' Post Status
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP Timestamp of creation
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP Last update timestamp

Table: comments

Column Name Data Type Constraints Description
comment_id BIGINT UNSIGNED PRIMARY KEY, AUTO_INCREMENT Unique Comment ID
post_id BIGINT UNSIGNED FOREIGN KEY -> posts(post_id), NOT NULL Related Post ID
user_id BIGINT UNSIGNED FOREIGN KEY -> users(user_id), NULLABLE Comment Author ID
comment TEXT NOT NULL Comment Content
status TINYINT(1) DEFAULT 1 1 = Approved, 0 = Pending
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP Timestamp of creation

Table: categories

Column Name Data Type Constraints Description
category_id BIGINT UNSIGNED PRIMARY KEY, AUTO_INCREMENT Unique Category ID
name VARCHAR(100) NOT NULL, UNIQUE Category Name
slug VARCHAR(100) NOT NULL, UNIQUE URL Slug
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP Timestamp of creation

Side Menu Table Schema (with Sub-Menus)

Table: side_menu

Column Name Data Type Constraints Description
menu_id BIGINT UNSIGNED PRIMARY KEY, AUTO_INCREMENT Unique Menu ID
parent_id BIGINT UNSIGNED NULLABLE, FOREIGN KEY -> side_menu(menu_id) Reference to Parent Menu ID (for sub-menus)
name VARCHAR(50) NOT NULL Menu Name
icon TEXT NOT NULL SVG Icon Data
permission_level TINYINT UNSIGNED NOT NULL Required Permission
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP Timestamp of creation

How it Works?

  • If parent_id is NULL, it’s a main menu item.
  • If parent_id has a value, it’s a sub-menu under the referenced menu_id.

Example Data

menu_id parent_id name icon permission_level
1 NULL Dashboard 🏠 1
2 NULL Settings βš™οΈ 2
3 2 Users πŸ‘₯ 2
4 2 Roles πŸ”‘ 2

Here, "Users" and "Roles" are sub-menus under "Settings". πŸš€

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay