Loading Depth Study
Preparing your workspace
CRUD operations are the fundamental database actions used by applications to manage stored data.
INSERT creates rows, SELECT reads rows, UPDATE changes existing rows, and DELETE removes rows. PostgreSQL also supports RETURNING, which can return affected rows immediately after INSERT, UPDATE, or DELETE. WHERE conditions are critical when modifying or removing records. Writing precise SQL helps prevent accidental changes to unrelated data.
A course system can create a course, retrieve it, update its title, and archive or delete it according to business rules.
INSERT INTO courses (id, title)
VALUES ('8c3e1d8c-1111-4444-8888-123456789abc', 'PostgreSQL Basics')
RETURNING id, title;
UPDATE courses
SET title = 'PostgreSQL Fundamentals'
WHERE id = '8c3e1d8c-1111-4444-8888-123456789abc'
RETURNING id, title;The course is inserted and then updated, with PostgreSQL returning the affected values.