Mohamed Reda Tech Logo
HomeArticlesApplicationsPhonesTutorialsTools
AR
Mohamed Reda Tech Logo
Mohamed Reda Tech

Tech articles, applications, and digital tools & services.

Follow Us
TelegramYouTube

Quick Links

ArticlesApplicationsTutorialsToolsPhones

Help

About UsAbout the authorEditorial policyContact Us

Stay Connected

Get notified when new articles, tools, and app updates are released.

© 2026 MR. All rights reserved.

Privacy Policy•Terms of Service•
Hands-On SQL Tutorial: Table Design, CRUD Operations, and Advanced Joins · Mohamed Reda Tech
  1. Home
  2. Tutorials
  3. Hands-On SQL Tutorial: Table Design, CRUD Operations, and Advanced Joins
Tutorials

Hands-On SQL Tutorial: Table Design, CRUD Operations, and Advanced Joins

Master Structured Query Language (SQL) through practical examples: table schema definitions, CRUD operations, WHERE filtering, aggregation, and relational JOIN operations.

By Mohamed RedaPublished: October 15, 2026Updated: November 14, 20263 min read
Relational Database Foreign Key Constraints and Join Matrix

The Universal Standard Language for Relational Data

Structured Query Language (SQL) remains the definitive, battle-tested standard for interacting with relational database management systems (RDBMS) such as PostgreSQL, MySQL, and SQLite. SQL allows software engineers to declare schema topologies, enforce referential integrity constraints, and query complex relational datasets containing millions of rows in milliseconds.

1. Schema Definition & Constraints (DDL)

Data Definition Language (DDL) commands establish table schemas, data types, and primary-foreign key relationships:

-- Define users table with primary key and unique email constraint
CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    email VARCHAR(255) UNIQUE NOT NULL,
    role VARCHAR(20) DEFAULT 'author',
    created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

-- Define articles table with foreign key cascade reference
CREATE TABLE articles (
    id SERIAL PRIMARY KEY,
    title VARCHAR(200) NOT NULL,
    slug VARCHAR(200) UNIQUE NOT NULL,
    author_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
    views_count INTEGER DEFAULT 0,
    is_published BOOLEAN DEFAULT false,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

2. Core CRUD Data Operations (DML)

Data Manipulation Language (DML) powers the four fundamental operations: Create, Read, Update, and Delete.

Create (INSERT)

INSERT INTO users (name, email, role) 
VALUES 
    ('Mohamed Reda', 'mohamed@example.com', 'admin'),
    ('Sara Ali', 'sara@example.com', 'author');

INSERT INTO articles (title, slug, author_id, views_count, is_published)
VALUES 
    ('Introduction to SQL Engines', 'intro-to-sql', 1, 1500, true),
    ('Modern Web Security Guide', 'web-security-guide', 2, 850, true);

Read & Filter (SELECT & WHERE)

-- Retrieve published articles with over 1000 views, ordered descending
SELECT title, views_count, created_at 
FROM articles
WHERE is_published = true AND views_count >= 1000
ORDER BY views_count DESC
LIMIT 10;

Update (UPDATE)

-- Increment view count atomically for a specific article
UPDATE articles 
SET views_count = views_count + 1 
WHERE slug = 'intro-to-sql';

Delete (DELETE)

-- Delete a specific record using indexed primary key
DELETE FROM articles 
WHERE id = 5;

3. Relational Table Joins (SQL JOINs)

The true power of relational engines lies in synthesizing normalized entities into cohesive analytical results:

-- Query articles alongside author profile details
SELECT 
    a.title,
    a.views_count,
    u.name AS author_name,
    u.email AS author_email
FROM articles a
INNER JOIN users u ON a.author_id = u.id
WHERE a.is_published = true;

-- Aggregate metrics: Count published articles per user
SELECT 
    u.name,
    COUNT(a.id) AS total_articles,
    COALESCE(SUM(a.views_count), 0) AS total_views
FROM users u
LEFT JOIN articles a ON u.id = a.author_id
GROUP BY u.id, u.name
ORDER BY total_views DESC;

Summary

SQL fluency is an enduring software engineering superpower. Whether tuning application ORM queries, designing production databases, or architecting enterprise data pipelines, mastering relational concepts ensures resilient and high-throughput systems.

Related articles

Tutorials

Google Find My Device guide: locate, lock, or erase your lost Android phone remotely

Lost or stolen phone? A practical guide to Google's Find My Device: what to set up before you lose it, how to locate, ring, lock, or erase it remotely, and the real limits of each option.

November 28, 20263 min read
Tutorials

Comments(0)

Leave a comment

Share your thoughts or questions. Your email will not be published.

No comments yet. Be the first to share your thoughts!

Frequently asked questions

What is the key difference between INNER JOIN and LEFT JOIN?+

An INNER JOIN returns only records where matching keys exist in both joined tables. A LEFT JOIN returns all records from the left table, populating missing values from the right table with NULL if no match exists.

What is a database index and why is it essential?+

An index is an auxiliary balanced tree data structure (typically B-Tree) created on specific columns. It transforms slow full table scans into logarithmic time lookups, dramatically accelerating read queries on large datasets.

Why must UPDATE and DELETE queries be authored with caution?+

Omitting a WHERE clause in an UPDATE or DELETE statement applies the operation unconditionally to every single row in the entire table, causing irreversible data modification or loss.

Translate Chrome Pages on Android: Choose a Language and Manage Automatic Translation

Request page translation, choose its destination language and manage automatic or excluded languages. Learn how these differ from Chrome’s interface language.

November 28, 20264 min read
Tutorials

Chrome Reading Mode on Android: Adjust Text, Fonts and Background Colors

Open Reading mode for supported pages, adjust font style and size, and choose light, sepia or dark backgrounds. Understand unavailable pages and the difference from audio playback.

November 24, 20264 min read
Tutorials

Android Privacy Dashboard: Review Camera and Microphone Use and Change Permissions

Find permission activity, identify the app and access time, then change one permission and test the feature. Understand Android 12 and 13 history windows and the limits of the log.

November 24, 20264 min read