CRUD Operations – Explained with Examples
1. What is CRUD?
CRUD stands for Create, Read, Update, and Delete — the four basic operations that can
be performed on data in any storage system, especially databases.
C - Create: Add new data
R - Read: Retrieve existing data
U - Update: Modify existing data
D - Delete: Remove data
2. Real-World Example: Student Database
We manage a student record system with the following fields:
- id (primary key)
- name
- age
- course
SQL Implementation (MySQL/PostgreSQL)
CREATE
INSERT INTO students (id, name, age, course)
VALUES (1, 'Alice', 20, 'Computer Science');
READ
SELECT * FROM students;
SELECT * FROM students WHERE id = 1;
UPDATE
UPDATE students
SET age = 21
WHERE id = 1;
DELETE
DELETE FROM students WHERE id = 1;
Python Dictionary-Based Example
# Sample database (dictionary)
students = {}
# 1. CREATE
students[1] = {'name': 'Alice', 'age': 20, 'course': 'Computer Science'}
# 2. READ
print("All students:", students)
print("Student ID 1:", [Link](1))
# 3. UPDATE
students[1]['age'] = 21
print("Updated student ID 1:", students[1])
# 4. DELETE
del students[1]
print("After deletion:", students)
Key Points
- SQL CRUD is used in relational databases.
- Python CRUD can be done with dictionaries or ORM libraries.
- CRUD operations form the foundation of backend development and REST APIs.