DEV Community

Cover image for Designing My First Real Database Schema with DDL (PostgreSQL)
Bharath Kumar_30
Bharath Kumar_30

Posted on

Designing My First Real Database Schema with DDL (PostgreSQL)

Hey everyone,

Today was a different kind of learning day for me.

Instead of writing APIs or working on frontend, I focused on something very important in backend development — database design using DDL commands.

At first, I thought database means just creating tables. But today I understood that it’s much more than that.


What I worked on today

My guide asked me to:

  • Design the database structure
  • Write DDL commands (CREATE TABLE)
  • Apply constraints (for data integrity)
  • Think about optimization

So I didn’t just create tables — I designed a proper structure for my project.


What is DDL?

DDL stands for Data Definition Language

It is used to define the structure of the database.

Some common commands:

CREATE TABLE
ALTER TABLE
DROP TABLE
Enter fullscreen mode Exit fullscreen mode

Today, I mainly worked with CREATE TABLE.


My Database Design (Project Based)

My project is about social media automation, so I designed tables based on real use cases.


Users Table

Stores user details like username, email, and password.

Important:

  • Email is unique
  • Password is stored securely

Platforms Table

Instead of hardcoding platforms like Telegram or Twitter, I created a separate table.

Benefit:

  • Easy to add new platforms later
  • No need to change code

Credentials Table

This table connects users and platforms.

Key points:

  • Stores API keys (in encrypted format)
  • Prevents duplicate connections using UNIQUE constraint
  • Uses ON DELETE CASCADE

Posts Table

Stores content that users want to post.

Includes:

  • Content
  • Status (pending, sent, failed)

Post Logs Table

This was a very important part.

One post can go to multiple platforms
Each platform result is stored separately

Example:

  • Telegram → Success
  • Twitter → Failed

So logs help track everything clearly.


Data Integrity (Important Learning)

Today I understood that just creating tables is not enough.

We must protect the data.

I used:

  • PRIMARY KEY → unique identification
  • FOREIGN KEY → relationships
  • UNIQUE → no duplicates
  • NOT NULL → required fields
  • CHECK → restrict valid values
  • ON DELETE CASCADE → automatic cleanup

Optimization (Small but powerful)

I also added indexes.

Why?

Because:

  • Faster queries
  • Better performance

What I realized today

Earlier, I used to think:

“Database = just store data”

Now I understand:

“Database design = foundation of the entire application”

If the structure is wrong, everything becomes difficult later.


My takeaway

  • Think before creating tables
  • Design based on real use cases
  • Always include constraints
  • Plan for scalability
  • Keep it clean and structured

Final thought

Today I didn’t just write SQL.

I learned how to think like a backend developer.

Still learning, still improving — one step at a time.

More updates coming soon

Top comments (0)