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 |
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.
Identify the record's status: The scenario says that the customer record already exists, so this is not a Create operation.
Identify the action: The record is being modified rather than merely retrieved or removed.
Map 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
Treating every database action as an UPDATE
Retrieving data is Read, not Update.
Fix:
Map Read to SELECT.Confusing a new record with a modified record
The scenario describes Create because the record is new.
Fix:
Map Create to INSERT.Confusing removal with modification
Removing data is Delete, not Update.
Fix:
Map Delete to DELETE.Remembering the CRUD word but not the SQL mapping
Each CRUD operation has a specific corresponding SQL command.
Fix:
Memorize 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
- CRUD stands for Create, Read, Update, and Delete.
- UPDATE is the CRUD operation for modifying an existing record.
- The SQL commands map directly as follows: Create to INSERT, Read to SELECT, Update to UPDATE, and Delete to DELETE.
- CRUD forms a complete framework for understanding how data is managed throughout its lifecycle.
- To classify a scenario, identify whether data is being added, retrieved, modified, or removed.
Key Takeaways
- 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.