INSERT, UPDATE, DELETE
Site Admin
· 11 Sep 2026
· 2 views
Adding Data With INSERT
INSERT INTO customers (name, email, city) VALUES
('Priya Sharma', 'priya@example.com', 'Mumbai');
INSERT INTO customers (name, email, city) VALUES
('Rahul Patel', 'rahul@example.com', 'Pune'),
('Anjali Rao', 'anjali@example.com', 'Hyderabad');Updating Data
UPDATE customers SET city = 'Bengaluru' WHERE id = 1;
UPDATE customers SET city = 'Pune', updated_at = NOW() WHERE email = 'rahul@example.com';Never run UPDATE without a WHERE clause unless you really mean every row.
Deleting Data
DELETE FROM customers WHERE id = 3;
DELETE FROM customers WHERE is_inactive = TRUE;Copying Between Tables
INSERT INTO vip_customers (name, email)
SELECT name, email FROM customers WHERE total_spend > 1000;Managing Conflicts (Upsert)
- PostgreSQL:
ON CONFLICT (email) DO UPDATE SET ... - MySQL:
ON DUPLICATE KEY UPDATE ... - SQLite:
ON CONFLICT ...(Postgres-style). - Oracle / SQL Server: MERGE statement.
Key Points
- INSERT adds rows; UPDATE changes them; DELETE removes them.
- Always pair UPDATE/DELETE with a WHERE clause.
- INSERT ... SELECT copies data between tables.
- Each database offers an upsert mechanism; they differ slightly.