DEV Community

naibei caleb
naibei caleb

Posted on

A Practical Introduction to SQL: DDL, DML, and Data Analysis

Table of Contents


Introduction

Structured Query Language (SQL) is the foundation of working with databases. This week’s work focused on understanding two major categories of SQL commands DDL and DML and applying them in a practical assignment involving a school database. Through this, I was able to create tables, manipulate data, filter results, and transform outputs using conditional logic.


What are DDL and DML?

DDL (Data Definition Language)

DDL refers to SQL commands used to define and manage the structure of a database. These commands control how data is stored.

Examples:

  • CREATE – used to create tables or databases
  • ALTER – used to modify existing structures
  • DROP – used to delete tables or databases

 Table structure after executing CREATE statement.

DML (Data Manipulation Language)

DML deals with the data inside the database. It allows you to insert, update, retrieve, and delete data.

Examples:

  • INSERT – adds new records
  • UPDATE – modifies existing records
  • DELETE – removes records
  • SELECT – retrieves data

 Populating tables using INSERT and verifying data

Difference

DDL focuses on the structure, while DML focuses on the data itself.

In simple terms, DDL builds the house, and DML manages what’s inside it.


Application of CREATE, INSERT, UPDATE, and DELETE

In this assignment, I used several SQL commands to build and manage a school database:

CREATE

I used the CREATE statement to define tables such as students, subjects, and exam_results.

INSERT

The INSERT statement was used to populate tables with data.

UPDATE

I used UPDATE to modify existing data.

 Updating existing records using UPDATE

DELETE

Used to remove incorrect or unnecessary records.

 Removing records using DELETE.


Filtering Data with WHERE

The WHERE clause is essential for retrieving specific data.

Operators used:

  • = → exact match
  • > → greater than
  • BETWEEN → range filtering
  • IN → multiple values
  • LIKE → pattern matching

 Filtering data using WHERE clause with different conditions.


Using CASE WHEN for Data Transformation

The CASE WHEN statement applies conditional logic.

Example classification:

  • Marks ≥ 80 → Distinction
  • Marks ≥ 60 → Merit
  • Marks ≥ 40 → Pass
  • Below 40 → Fail

 Transforming data using CASE WHEN logic.


Reflection

This week was both challenging and rewarding. Errors like incorrect column names and missing tables helped me understand how strict SQL is and the importance of attention to detail.


Conclusion

Understanding DDL and DML is fundamental to working with databases. Practicing SQL commands and applying them in real scenarios helped strengthen my skills and confidence.

Top comments (0)