SQL and DatabasesBeginner7 min read read

SQL Basics for Beginners: Relational Database Fundamentals

Understand tables, rows, columns, primary keys, and core CRUD statements across modern databases.

Coding Hub Technical Editorial Team(Software Engineering & Education)
•
Updated 2026-03-08

Overview & Context

Structured Query Language (SQL) is the universal, standardized language used to manage, store, query, and manipulate data stored in relational databases. First developed by IBM researchers in the 1970s, SQL remains the absolute foundation of data infrastructure across modern banking, e-commerce, cloud software, and analytics platforms.

What You Will Learn
Understand what a Relational Database Management System (RDBMS) is
Learn table schema structure: rows, columns, data types, and primary keys
Write fundamental DDL and DML statements: CREATE, INSERT, and SELECT
Understand standard SQL dialects across PostgreSQL, MySQL, and SQLite

1. What is an RDBMS?

Relational integrity, ACID compliance, and structured storage

A Relational Database Management System (RDBMS) organizes structured data into two-dimensional tables consisting of horizontal rows (records) and vertical columns (fields).

Relational databases guarantee ACID properties (Atomicity, Consistency, Isolation, Durability), ensuring that financial transactions and critical database operations either succeed completely or roll back without corrupting data.

2. Tables, Columns, and Primary Keys

Every column in a database table has a strictly defined data type (e.g. `INTEGER`, `VARCHAR`, `DECIMAL`, `BOOLEAN`, `TIMESTAMP`).

A Primary Key is a unique identifier assigned to each row in a table. No two rows can share the same primary key value, and a primary key cannot be `NULL`.

3. Creating Tables & Inserting Records

Data Definition Language (DDL) and Data Manipulation Language (DML)

Use `CREATE TABLE` to define your table schema, and `INSERT INTO` to populate it with new rows:

sql
-- Create student directory table
CREATE TABLE students (
    student_id SERIAL PRIMARY KEY,
    first_name VARCHAR(50) NOT NULL,
    last_name VARCHAR(50) NOT NULL,
    email VARCHAR(100) UNIQUE NOT NULL,
    cgpa DECIMAL(3, 2) DEFAULT 0.00,
    enrolled_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Insert sample records
INSERT INTO students (first_name, last_name, email, cgpa)
VALUES 
    ('Sarah', 'Chen', 'sarah.c@university.edu', 8.95),
    ('Marcus', 'Vance', 'marcus.v@university.edu', 7.40),
    ('Aisha', 'Patel', 'aisha.p@university.edu', 9.20);
Key note: SERIAL (or AUTOINCREMENT in SQLite) automatically increments the unique student_id integer for every inserted row.

4. Executing Basic SELECT Queries

To retrieve information from a database, execute a `SELECT` statement. You can specify exact column names or use the wildcard `*` to fetch all columns:

sql
-- Fetch specific columns
SELECT first_name, email, cgpa
FROM students;

-- Fetch all columns from the table
SELECT * FROM students;
Key note: In production software, avoid `SELECT *`. Explicitly naming required columns reduces network bandwidth and query latency.
Common Mistake to Avoid
  • Executing `UPDATE` or `DELETE` statements without a `WHERE` clause. Doing so will overwrite or permanently delete every single row in the entire table!

5. SQL Dialects & Database Engines

While ANSI SQL establishes standard syntax, individual database engines (PostgreSQL, MySQL, SQLite, Microsoft SQL Server, Oracle) include minor syntax variations, specialized date functions, and custom performance extensions.

Summary & Key Takeaways

  • 1SQL is the declarative query language for relational databases.
  • 2Data is organized in 2D tables of rows and typed columns.
  • 3Primary keys uniquely identify records and enforce relational integrity.
  • 4Always specify explicit column names rather than `SELECT *` in production code.
Frequently Asked Questions

Is SQL case-sensitive?

Standard SQL keywords (like SELECT, FROM, WHERE) are case-insensitive, but writing them in UPPERCASE is the universal industry convention. Table and column names may be case-sensitive depending on your database engine configuration and OS filesystem.

What is the difference between SQL and NoSQL?

SQL databases are relational, structured, and use fixed schemas with ACID guarantees. NoSQL databases (like MongoDB, Redis, Cassandra) store unstructured or semi-structured data (JSON documents, key-value pairs) and prioritize horizontal scaling flexibility over relational joins.