Concepts / DELETE: Removing Data from Tables

DELETE: Removing Data from Tables

CRUD is not limited to one type of application. A social media platform, banking system, contact manager, e-commerce database, or other database application relies on the same four fundamental operations.

  • Programming

Why CRUD Matters

A database application constantly manages data. It may add new data, retrieve existing data, modify stored data, or remove data that is no longer needed. These four fundamental operations are grouped under the acronym CRUD: Create, Read, Update, and Delete. CRUD provides a simple framework for understanding what a database application is doing whenever it works with data.

Key point

CRUD is not limited to one type of application. A social media platform, banking system, contact manager, e-commerce database, or other database application relies on the same four fundamental operations.

CreateINSERTReadSELECTUpdateUPDATEDeleteDELETEmaps tomaps tomaps tomaps to
Which SQL command corresponds to Create, Read, Update, and Delete?

The Four Operations

CRUD operationPurposeSQL command
CreateAdds new dataINSERT
ReadRetrieves dataSELECT
UpdateModifies existing dataUPDATE
DeleteRemoves dataDELETE

Each CRUD operation maps to a specific SQL command.

The CRUD names describe the data-management goal, while the SQL command names identify the command associated with that goal. If an application needs to add a new product record, the operation is Create and the corresponding SQL command is INSERT. If it needs to retrieve temperature data, the operation is Read and the corresponding command is SELECT. Modifying an existing customer record is Update, which maps to UPDATE. Removing an email record is Delete, which maps to DELETE.

CreateINSERTReadSELECTUpdateUPDATEDeleteDELETEdata existsdata may changedata may be removed
How are Create, Read, Update, and Delete connected as the complete lifecycle of managing data?

A Customer Record Through CRUD

Worked example

One record, four possible operations

Trace how a customer record in an e-commerce database can move through the CRUD lifecycle.

  1. 1
    Create

    A new customer record is added to the e-commerce database. This is the Create operation, which maps to INSERT.

  2. 2
    Read

    The application retrieves the customer record when it needs to use the stored data. This is the Read operation, which maps to SELECT.

  3. 3
    Update

    The existing customer record is modified. This is the Update operation, which maps to UPDATE.

  4. 4
    Delete

    The customer record is removed when the data is no longer retained in the table. This is the Delete operation, which maps to DELETE.

Result

The same record can experience Create, Read, Update, and Delete during its existence. Together, these operations describe its complete data-management lifecycle.

Data taskAdd new dataCreate / INSERTRetrieve dataRead / SELECTModify existing dataUpdate / UPDATERemove dataDelete / DELETEaddingretrievingmodifyingremoving
Given a data-management task, how do I determine whether it requires Create, Read, Update, or Delete?

What DELETE Represents

DELETE is the CRUD operation used when data is being removed from a table. In the CRUD-to-SQL mapping, Delete corresponds directly to the SQL command DELETE. The important distinction is the intended action: the application is not adding data, retrieving it, or modifying an existing record. It is removing data.

Customer recordCustomer recordEmail recordEmail recordremainsDELETE
What changes in a table before and after a DELETE operation removes a row?
In the real world

Removing an email record is a Delete scenario. The task is not to retrieve the email or modify its contents; the data-management goal is to remove it, so the CRUD operation is Delete and the corresponding SQL command is DELETE.

Choosing the Correct Operation

EASY

Classify each scenario as Create, Read, Update, or Delete, then identify its SQL command: retrieving a user's balance; adding a new product record; modifying an existing customer record; removing an email record; retrieving temperature data; adding a new patient record.

Hints
  • Ask whether the scenario adds, retrieves, modifies, or removes data.
  • After identifying the CRUD operation, use the CRUD-to-SQL mapping.
ScenarioCRUD operationSQL command
Retrieving a user's balanceReadSELECT
Adding a new product recordCreateINSERT
Modifying an existing customer recordUpdateUPDATE
Removing an email recordDeleteDELETE
Retrieving temperature dataReadSELECT
Adding a new patient recordCreateINSERT

Classifications for the practice scenarios.

  • Common mistake

    Treating CRUD names and SQL command names as unrelated concepts.

    What it looks like

    Choosing a command without first identifying whether the task creates, reads, updates, or deletes data.

    Why it fails

    Each CRUD operation maps directly to a specific SQL command.

    Do this instead

    Classify the task first, then apply the mapping: Create to INSERT, Read to SELECT, Update to UPDATE, and Delete to DELETE.

  • Common mistake

    Calling a retrieval task Delete because the application is working with stored data.

    What it looks like

    Retrieving a user's balance.

    Why it fails

    Retrieving data is the Read operation, not the Delete operation.

    Do this instead

    Use Read and SELECT when the task retrieves data.

  • Common mistake

    Calling a modification task Create because the application is producing a changed result.

    What it looks like

    Modifying an existing customer record.

    Why it fails

    The record already exists; the task changes existing data.

    Do this instead

    Use Update and UPDATE for an existing record that is being modified.

CRUD Takeaways

  1. 1
    CRUD stands for Create, Read, Update, and Delete.
  2. 2
    The four operations map to INSERT, SELECT, UPDATE, and DELETE respectively.
  3. 3
    CRUD describes the complete framework and lifecycle of managing data.
  4. 4
    Choose the operation by identifying whether the task adds, retrieves, modifies, or removes data.
  5. 5
    DELETE is the SQL command associated with removing data from tables.

At a glance

  • CRUD groups the four fundamental database operations: Create, Read, Update, and Delete.
  • The matching SQL commands are INSERT, SELECT, UPDATE, and DELETE.
  • Together, CRUD operations describe how data is added, retrieved, modified, and removed throughout its lifecycle.
  • A task involving removal of data is Delete in CRUD terms and uses DELETE in SQL terms.

More concepts starting with D