Skip to main content

Command Palette

Search for a command to run...

SQL Basics for Backend Developers: CREATE, SELECT, INSERT, DELETE, JOIN, and More.

Published
4 min readView as Markdown
SQL Basics for Backend Developers: CREATE, SELECT, INSERT, DELETE, JOIN, and More.
S

Tech enthusiast writing about code, data, and ideas. Writing to learn, simplify, and stay curious, one post at a time.

Databases are the heart of most modern web applications. Whether you're building a blog, an e-commerce site, or a SaaS tool, you'll need to store and retrieve data — and that’s where SQL (Structured Query Language) comes in. For backend developers, SQL isn’t just helpful — it’s essential.

In this guide, you’ll learn the basic SQL commands every backend developer must know. We'll explore key operations like CREATE, SELECT, INSERT, DELETE, and JOIN, with clear examples and backend context.

1. What is SQL?

SQL, short for Structured Query Language, is the standard programming language used to manage and manipulate relational databases. In simple terms, SQL lets you talk to a database.

Imagine your backend application as the brain and the database as long-term memory. SQL is the language your backend uses to ask the memory questions, store answers, update facts, or forget things it no longer needs.

What Kind of Databases Use SQL?

SQL is used with relational database management systems (RDBMS) — where data is stored in structured tables with rows (records) and columns (attributes). Think of Excel spreadsheets — but much more powerful and scalable.

Popular RDBMS that use SQL:

  • PostgreSQL (open source, widely used in startups and production)

  • MySQL / MariaDB (used in WordPress, LAMP stack)

  • SQLite (lightweight, often used in mobile apps or local dev)

  • Microsoft SQL Server (used in many enterprise systems)

  • Oracle DB (used in large-scale legacy enterprise apps)

Why Should Backend Developers Care About SQL?

As a backend developer, you:

  • Handle user data, transactions, logs, and relationships.

  • Build APIs that store, fetch, update, or delete data.

  • Need to optimize queries for performance.

  • Manage data consistency, security, and integrity.

All of this happens through SQL, either directly (writing raw queries) or indirectly (using an ORM like Sequelize, Prisma, or SQLAlchemy).

Let’s Look At Various SQL Commands

CREATE – Defining Your Tables

CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  name VARCHAR(100),
  email VARCHAR(100) UNIQUE,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
  • VARCHAR(100): A variable-length string column that can store up to 100 characters.

  • PRIMARY KEY: A column (or set of columns) that uniquely identifies each row in the table and cannot be NULL.

  • UNIQUE: Ensures all values in the column are different — no duplicates allowed.

    Backend Insight:
    Think of CREATE TABLE as defining your database’s schema — just like defining classes in backend logic. You set data types, constraints, and default values.

INSERT – Adding New Records

Once your table is ready, start inserting data.

INSERT INTO users (name, email)
VALUES ('Jane', 'Jane@example.com');

You can add multiple rows at once:

INSERT INTO users (name, email)
VALUES 
('Satya', 'satya@domain.com'),
('Riya', 'riya@domain.com');

Backend Insight:
This is often done in your API’s POST route — where the server receives data and saves it to the database.

SELECT – Reading Data (The Most Used)

Fetch specific columns or all records:

SELECT * FROM users;
SELECT name, email FROM users;

Add conditions with WHERE:

SELECT * FROM users WHERE name = 'Jane';

Backend Insight:
Used in GET routes. Often combined with pagination, filtering, or search.

UPDATE – Modifying Records

UPDATE users 
SET name = 'Jane D.' 
WHERE id = 1;

Backend Insight:
Used in PUT/PATCH routes — e.g., editing user profile, updating inventory, etc.

DELETE – Removing Data

DELETE FROM users WHERE id = 2;

Be cautious — without a WHERE clause, it deletes everything!

Backend Insight:
Used in DELETE routes. Some systems implement “soft deletes” by adding a deleted_at timestamp instead of deleting the row.

JOIN – Combining Tables

Imagine you have another table:

CREATE TABLE orders (
  id SERIAL PRIMARY KEY,
  user_id INT REFERENCES users(id),
  product VARCHAR(100),
  order_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Fetch user details alongside their orders:

SELECT users.name, orders.product, orders.order_date
FROM users
JOIN orders ON users.id = orders.user_id;

Types of JOINs:

  • INNER JOIN: Returns records that have matches in both tables.

  • LEFT JOIN: Returns all users and their orders if any (includes users with no orders).

  • RIGHT JOIN: Vice-versa.

  • FULL JOIN: Combines all matches + non-matches from both sides.

Backend Insight:
This is how you "connect" foreign key relations in backend logic — replacing multiple queries with one optimized JOIN query.

Aggregate Functions and Grouping

Useful for analytics or summaries:

SELECT user_id, COUNT(*) as total_orders
FROM orders
GROUP BY user_id;

Other useful functions:

  • COUNT()

  • SUM()

  • AVG()

  • MAX(), MIN()

Security Tips for Backend Devs

  • Use prepared statements to prevent SQL Injection.

  • Always validate and sanitize user input.

  • Use ORMs like Sequelize (Node.js) or SQLAlchemy (Python) if you're not writing raw SQL.

  • Be mindful of N+1 query problems when working with JOINs.

Conclusion

SQL may seem intimidating at first, but with practice, it becomes second nature — especially when you're building the backend of a dynamic application. From creating tables to fetching complex relationships with JOINs, SQL is the silent engine that powers your backend data flow.

More from this blog

T

Tech Tales by Sreja

16 posts

Demystifying tech with clarity and code. Sreja Chakraborty shares insights on development, AI, systems and scientific concepts—written for learners, by a learner.