CRUD Operations
CRUD stands for Create, Read, Update and Delete. These are the four basic operations performed on data stored in a database.
Almost every database-driven application uses CRUD operations. In a Student Management System, for example, we can create a student record, read student information, update student details and delete a student record.
What is CRUD?
CRUD is a commonly used term in software development for describing the four fundamental operations performed on persistent data.
| Operation | Meaning | Purpose | Common SQL Command |
|---|---|---|---|
| Create | Add new data | Creates a new record. | INSERT |
| Read | Retrieve data | Reads existing records. | SELECT |
| Update | Modify data | Changes an existing record. | UPDATE |
| Delete | Remove data | Deletes an existing record. | DELETE |
CRUD Operations Flow
The four CRUD operations can be understood using the following flow:
CRUD
|
--------------------------------
| | |
CREATE READ UPDATE
| | |
INSERT SELECT UPDATE
|
-------------------------------
|
DELETE
|
DELETE
1. Create
The Create operation is used to add new records to a database table.
In SQL Server, the INSERT statement is commonly used to perform the Create operation.
INSERT INTO Students
(
StudentId,
StudentName,
Age
)
VALUES
(
101,
'Rahul',
22
);
2. Read
The Read operation is used to retrieve existing data from a database table.
In SQL Server, the SELECT statement is used to read data.
SELECT *
FROM Students;
3. Update
The Update operation is used to modify existing data in a database table.
In SQL Server, the UPDATE statement is used to modify existing records.
UPDATE Students
SET Age = 23
WHERE StudentId = 101;
4. Delete
The Delete operation is used to remove existing records from a database table.
In SQL Server, the DELETE statement is commonly used for this operation.
DELETE FROM Students
WHERE StudentId = 101;
CRUD in Student Management System
Let's understand CRUD using a Student Management System.
| Requirement | CRUD Operation | SQL Command |
|---|---|---|
| Add a new student | Create | INSERT |
| Display student details | Read | SELECT |
| Change student details | Update | UPDATE |
| Remove a student | Delete | DELETE |
CRUD Lifecycle
User
|
↓
Create Data
|
↓
Database
|
↓
Read Data
|
↓
Update Data
|
↓
Delete Data
CRUD and SQL Commands
| CRUD | SQL Command | Action |
|---|---|---|
| Create | INSERT | Add record |
| Read | SELECT | Retrieve record |
| Update | UPDATE | Modify record |
| Delete | DELETE | Remove record |
Important
CRUD operations form the foundation of database-driven applications. In real-world applications, these operations are usually performed through application interfaces such as web pages, APIs or backend services.
Summary
CRUD stands for Create, Read, Update and Delete. Create uses INSERT to add data, Read uses SELECT to retrieve data, Update uses UPDATE to modify data and Delete uses DELETE to remove data. These four operations are fundamental to most database-driven applications.