DEV Community

Cover image for Understanding Databases: SQL, NoSQL, DDL, and DML
De' Clerke
De' Clerke

Posted on

Understanding Databases: SQL, NoSQL, DDL, and DML

Databases sit at the core of every modern application. Whether you're building a social media platform, an online store, or a data pipeline, you need a reliable way to store, organize, and access information. Let’s break down the essentials.


What is a Database?

A database is an organized collection of data that can be stored, managed, and retrieved efficiently. Instead of scattering data across files or spreadsheets, databases provide a structured system where data can be queried, updated, and maintained consistently.


Types of Databases

Databases come in many flavors, but the two most common categories are SQL (relational) and NoSQL (non-relational).

1. SQL Databases

  • Structure: Tables with rows and columns.
  • Examples: MySQL, PostgreSQL, Oracle, SQL Server.
  • Strengths:
    • Strong consistency and reliability.
    • Support for complex queries and relationships (joins).
    • Schema-based design ensures data integrity.

2. NoSQL Databases

  • Structure: Can be document-based, key-value pairs, wide-column stores, or graph databases.
  • Examples: MongoDB (document), Redis (key-value), Cassandra (wide-column), Neo4j (graph).
  • Strengths:
    • Flexible schema (data doesn’t need to fit into fixed tables).
    • Handles unstructured or semi-structured data.
    • Scales horizontally with ease, often preferred in big data and real-time apps.


When to Use SQL vs NoSQL

  • Use SQL when:

    • Data is highly structured with clear relationships.
    • You need ACID transactions (e.g., banking, e-commerce checkout).
    • Queries involve complex joins and aggregations.
  • Use NoSQL when:

    • Data is semi-structured, rapidly changing, or unstructured.
    • Applications need high scalability and performance at massive scale.
    • You’re working with big data, caching, or real-time analytics.

👉 Think of it this way:

  • SQL = consistency and structure.
  • NoSQL = flexibility and speed.

DDL vs DML

Within databases, two key categories of SQL commands are DDL and DML:

  • DDL (Data Definition Language):

    • Defines and manages database structures like tables, schemas, indexes.
    • Examples: CREATE, ALTER, DROP.
    • Think of DDL as designing the blueprint of your database.
  • DML (Data Manipulation Language):

    • Works with the actual data inside the structures.
    • Examples: INSERT, UPDATE, DELETE, SELECT.
    • Think of DML as filling in and editing the content.

Example: DDL and DML in Action


sql
-- DDL Example: Create a table
CREATE TABLE Users (
    id INT PRIMARY KEY,
    name VARCHAR(100),
    email VARCHAR(100) UNIQUE
);

-- DML Example: Insert and query data
INSERT INTO Users (id, name, email)
VALUES (1, 'Alice', 'alice@example.com');

SELECT * FROM Users;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)