PostgreSQL Update & Delete
PostgreSQL Update & Delete
1. PostgreSQL Update
Revise Row Content
Use the UPDATE command to revise field entries in previously stored rows.
Illustration
Change the paint value of the entry where brand equals 'Volvo':
UPDATE vehicles SET paint = 'crimson' WHERE maker = 'Volvo';
Effect
UPDATE 1
→ Indicates a single line was changed by this action.
Caution
The WHERE segment limits which lines are altered—without it, multiple or all matches may be modified.
Inspect Output
To view how things changed, run a command to display everything:
SELECT * FROM vehicles;
2. PostgreSQL Delete
Erase Table Entries
The DELETE operation is employed to remove data rows from an existing dataset.
Important Reminder
Use caution when erasing content. The condition following WHERE defines the target entries to eliminate.
If no filtering condition is included, every item in the dataset will be wiped.
Sample Operation
Eliminate any rows where maker is ‘Volvo’:
DELETE FROM autos WHERE maker = 'Volvo';
Outcome
DELETE 1
→ Implies one entry has been removed.
View Current Data
Execute the below line to examine the current state of the table:
SELECT * FROM autos;
Clear Entire Dataset
You may strip all content from the table while retaining its blueprint (structure, fields, etc).
Example Removal
Purge the full content from the autos table:
DELETE FROM autos;
Result Shown
DELETE 3
→ Confirms that 3 entries have been purged.
Inspect Again
Use the same fetch command to verify:
SELECT * FROM autos;
Alternative Shortcut
The same outcome can be produced with the TRUNCATE command, which is a faster way to empty the table.
Quick Format
Clear all records from the autos structure:
TRUNCATE TABLE autos;
Result Noted
TRUNCATE TABLE
Final Check
Display what remains (likely nothing):
SELECT * FROM autos;
Prefer Learning by Watching?
Watch these YouTube tutorials to understand POSTGRESQL Tutorial visually:
What You'll Learn:
- 📌 PgSQL Update Query | PgSQL Update Statement | How to Use Update Query in PgSQL | Simplilearn
- 📌 PostgreSQL Tutorial for Beginners 16 - PostgreSQL DELETE