UPDATE: Modifying Existing Data
CRUD is an acronym representing the four fundamental database operations: Create, Read, Update, and Delete.
One Record, Four Possible Operations
A database application manages data repeatedly throughout the data's existence. A record may be added, retrieved, changed, and eventually removed. These four fundamental operations are known together as CRUD: Create, Read, Update, and Delete. The focus of this article is UPDATE, the operation used when an existing record is modified.
The Complete Data Lifecycle
CRUD provides a complete framework for thinking about data management. Create adds a new record, Read retrieves data, Update modifies an existing record, and Delete removes a record. Together, these operations describe how data moves through its lifecycle in database applications.
Consider a customer record in an e-commerce database. The record can first be created, later read by the application, updated when existing customer information changes, and eventually deleted. This example shows why CRUD is described as a lifecycle rather than as a single database action.
CRUD and SQL Commands
Each CRUD operation maps directly to a SQL command. This mapping connects the general idea of managing data with the concrete commands that databases understand and execute.
| CRUD operation | Purpose | SQL command |
|---|---|---|
| Create | Add a new record | INSERT |
| Read | Retrieve data | SELECT |
| Update | Modify an existing record | UPDATE |
| Delete | Remove a record | DELETE |
The four CRUD operations and their corresponding SQL commands
What Changes During UPDATE
An UPDATE operation acts on data that already exists. The record remains part of the database, but one or more of its existing values are modified. The important distinction is that UPDATE changes an existing record; it does not represent the creation of a new record.
Classifying a changed customer record
An existing customer record in an e-commerce database is modified.
- 1Identify the record's status
The scenario says that the customer record already exists, so this is not a Create operation.
- 2Identify the action
The record is being modified rather than merely retrieved or removed.
- 3Map the operation to SQL
Modifying an existing record is Update, and Update maps to the SQL command UPDATE.
CRUD operation: Update. SQL command: UPDATE.
Choosing the Operation
To classify a data-management scenario, focus on the action being performed. Ask whether the application is adding a new record, retrieving data, modifying an existing record, or removing a record. After identifying the action, use the CRUD-to-SQL mapping to select the corresponding command.
| Scenario | CRUD operation | SQL command |
|---|---|---|
| A user retrieves their balance | Read | SELECT |
| A new product record is added | Create | INSERT |
| An existing customer record is modified | Update | UPDATE |
| An email record is removed | Delete | DELETE |
| Temperature data is retrieved | Read | SELECT |
| A new patient record is added | Create | INSERT |
Classifying common data-management scenarios
Classify each scenario as Create, Read, Update, or Delete, then name the matching SQL command: an existing customer record is changed.
Hints
- Look for whether the record already exists.
- The key action is changed or modified.
- After identifying the CRUD operation, use the CRUD-to-SQL mapping.
Answer: Update, which maps to UPDATE.Mistakes in CRUD Classification
Common mistake Treating every database action as an UPDATE
What it looks likeA user retrieves their balance.
Why it failsRetrieving data is Read, not Update.
Do this insteadMap Read to SELECT.
Common mistake Confusing a new record with a modified record
What it looks likeA new product record is added.
Why it failsThe scenario describes Create because the record is new.
Do this insteadMap Create to INSERT.
Common mistake Confusing removal with modification
What it looks likeAn email record is removed.
Why it failsRemoving data is Delete, not Update.
Do this insteadMap Delete to DELETE.
Common mistake Remembering the CRUD word but not the SQL mapping
What it looks likeCalling the operation Update but selecting INSERT as its SQL command.
Why it failsEach CRUD operation has a specific corresponding SQL command.
Do this insteadMemorize the complete mapping: Create–INSERT, Read–SELECT, Update–UPDATE, Delete–DELETE.
Separate two questions when reading a scenario: What happened to the data, and which SQL command represents that action? This prevents the operation's meaning from being confused with its command name.
Key Takeaways
- 1CRUD stands for Create, Read, Update, and Delete.
- 2UPDATE is the CRUD operation for modifying an existing record.
- 3The SQL commands map directly as follows: Create to INSERT, Read to SELECT, Update to UPDATE, and Delete to DELETE.
- 4CRUD forms a complete framework for understanding how data is managed throughout its lifecycle.
- 5To classify a scenario, identify whether data is being added, retrieved, modified, or removed.
At a glance
- CRUD describes the four fundamental database operations: Create, Read, Update, and Delete.
- UPDATE modifies an existing record rather than adding, retrieving, or removing one.
- The SQL command for Update is UPDATE.
- The complete CRUD mapping is Create–INSERT, Read–SELECT, Update–UPDATE, and Delete–DELETE.
- Identifying the action in a scenario is the first step toward choosing the correct CRUD operation.