Course topics

By WebNest Studio Engineering Team

Database and SQL Tutorial

Database Fundamentals

A database is an organized collection of data that is stored, managed, and retrieved electronically, and a Database Management System (DBMS) is the software layer that sits between an application and that stored data. Instead of an application reading and writing raw files directly, it talks to a DBMS, which handles storage, retrieval, concurrent access, security, and consistency on the application's behalf.

Before DBMSs became standard, applications stored data in flat files (plain text or binary files), and every program that needed the data had to implement its own logic for searching, updating, and preventing corruption when two processes wrote at once. This led to duplicated logic, inconsistent data, and fragile systems. A DBMS solves this once, centrally, so every application built on top of it inherits reliable data handling for free.

Why it matters

Almost every application you will build stores its data in a database: users, orders, messages, payments. A database keeps that data safe when the program stops, lets many users work at once, and answers questions about the data quickly. SQL is the language for talking to it, and it has stayed essentially the same for decades.

What a DBMS Actually Does

A DBMS provides a defined set of guarantees and services so that applications do not need to reinvent them.

  • Data storage and retrieval — organizes data on disk and provides efficient ways to find it (indexes, query optimization).
  • Concurrency control — allows many users or processes to read and write data at the same time without corrupting it.
  • Data integrity — enforces rules (constraints) so invalid data cannot be saved, such as a negative age or a duplicate email.
  • Security and access control — restricts which users or applications can read or modify which data.
  • Backup and recovery — protects against data loss from crashes, power failure, or hardware faults.

Relational Databases and SQL

A relational database organizes data into tables made of rows and columns, based on the relational model proposed by E. F. Codd in 1970. SQL (Structured Query Language) is the standard language used to define, query, and manipulate data in a relational database. Popular relational database systems include PostgreSQL, MySQL, Microsoft SQL Server, and Oracle Database — all of them understand a large common core of standard SQL, even though each adds its own extensions.

SQL Databases vs. NoSQL Databases

SQL (relational) databases enforce a fixed schema — every row in a table has the same columns and column types — and they excel at representing structured data with clear relationships, using SQL to query across tables. NoSQL databases (such as document, key-value, or graph databases) relax or remove the fixed schema, trading some consistency guarantees for flexibility and horizontal scalability. Neither is universally "better" — relational databases are usually the right default for data with clear structure and relationships, such as orders, customers, and inventory, while NoSQL options often fit unstructured or extremely high-volume data better.

Example

Creating a simple table and inserting a row using standard SQL

SQL
CREATE TABLE employees (
    id INTEGER PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    department VARCHAR(50)
);

INSERT INTO employees (id, name, department)
VALUES (1, 'Asha Rao', 'Engineering');

SELECT * FROM employees;
Output
Returns 1 row: (1, Asha Rao, Engineering)

Common Mistakes

  • Treating "database" and "DBMS" as the same thing — the database is the data itself; the DBMS is the software that manages it.
  • Assuming SQL only works with one specific product — standard SQL syntax (CREATE TABLE, SELECT, INSERT) works, with minor variations, across PostgreSQL, MySQL, SQL Server, and Oracle.
  • Choosing a NoSQL database purely because it sounds more modern, without evaluating whether the data actually has a clear relational structure.

Exercise

Create a books table with an integer primary key id, a title that cannot be empty, and a numeric price. Insert two books: Clean Code at 450 and SQL Basics at 90. Then select the titles of the books that cost more than 100.

Expected output: title then Clean Code

SQL · starter code
-- TODO: create the books table (id, title, price)

-- TODO: insert the two books

-- TODO: select the title of each book priced above 100
Show hints
  • NOT NULL after the column type makes a value mandatory.
  • Rows are filtered with a WHERE clause: WHERE price > 100.
Show solution
SQL · solution
CREATE TABLE books (
  id INTEGER PRIMARY KEY,
  title TEXT NOT NULL,
  price INTEGER
);

INSERT INTO books (id, title, price) VALUES (1, 'Clean Code', 450), (2, 'SQL Basics', 90);

SELECT title FROM books WHERE price > 100;

Quick quiz

1. What does SQL stand for?

  • A. Simple Query Logic
  • B. Standard Question Language
  • C. Sequential Query Layer
  • D. Structured Query Language
Show answer

D. It is the standard language for relational databases.

2. Which of these is a relational database?

  • A. PostgreSQL
  • B. MongoDB
  • C. Redis
  • D. Elasticsearch
Show answer

A. MongoDB is a document store, Redis a key-value store and Elasticsearch a search engine.

3. What is the main job of a DBMS?

  • A. To design web pages
  • B. To store data and manage access to it safely and efficiently
  • C. To compile programs
  • D. To send email
Show answer

B. It handles storage, queries, concurrent users, security and recovery after a crash.

Interview questions

What is the difference between SQL and NoSQL databases?

Show answer

SQL, or relational, databases store data in tables with a fixed schema, relate tables through keys, and support joins and transactions with strong consistency. NoSQL covers several other models: documents, key-value pairs, wide columns and graphs. They usually have flexible schemas and scale out across servers easily, often with weaker consistency guarantees. Relational databases suit structured, related data; NoSQL suits flexible or very high-volume data with simple access patterns.

Why use a database instead of files?

Show answer

A database lets many users read and write at the same time without corrupting data, finds rows quickly through indexes instead of scanning everything, enforces rules such as uniqueness and required values, groups changes into transactions that either complete fully or not at all, controls who may see what, and recovers cleanly after a crash. Plain files give none of this without a great deal of extra code.

Key Points to Remember

  • A DBMS manages storage, retrieval, concurrency, integrity, and security so applications do not implement these themselves.
  • Relational databases store data in tables of rows and columns and are queried using SQL.
  • SQL databases enforce a fixed schema; NoSQL databases trade schema rigidity for flexibility and scale.

Practice in the playground

Write and run your own code for this topic, or start from the exercise or an example. Runs your SQL on SQLite in your browser. Standard SQL works; a few features that exist only in PostgreSQL or MySQL do not. Your code for each topic is kept in this browser.

Run the examples

Change an input, predict the result, then compare it with the output. Explain why the result changes.

These examples need a project environment on your computer, so they can be copied but not run here. Codelab runs Python, FastAPI backends with SQLite, plain Java 17 and HTML/CSS/JavaScript.

WebNest Studio

Written by

WebNest Studio Engineering Team

Practical lessons from developers working with Java, Python, React, databases and production systems.

Led by Vansh Duggal, Founder, WebNest Studio · Full-stack & software engineering