SQL INSERT, UPDATE, DELETE – Modify Data in Tables




📝 Modify Data in Tables

After creating tables with SQL CREATE, ALTER, DROP, the next step is working with the data itself. SQL provides three powerful commands to manage records:

  • INSERT → Add new records
  • UPDATE → Change existing records
  • DELETE → Remove records

1️⃣ SQL INSERT – Adding New Records

The INSERT INTO statement adds new rows to a table.

Basic INSERT Example

INSERT INTO Employees (EmpID, FirstName, LastName, Salary, JoinDate)
VALUES (101, 'John', 'Doe', 55000, '2025-09-10');

Insert Multiple Rows

INSERT INTO Employees (EmpID, FirstName, LastName, Salary, JoinDate)
VALUES 
(102, 'Alice', 'Smith', 60000, '2025-09-12'),
(103, 'David', 'Brown', 58000, '2025-09-15');
Tip: Always mention column names in INSERT statements – it prevents errors if the table structure changes.

2️⃣ SQL UPDATE – Modifying Records

The UPDATE statement changes values in existing rows. Use WHERE to update only specific rows.

Update One Column

UPDATE Employees
SET Salary = 65000
WHERE EmpID = 102;

Update Multiple Columns

UPDATE Employees
SET Salary = 70000, LastName = 'Johnson'
WHERE EmpID = 103;
⚠️ Warning: If you skip the WHERE clause, all rows in the table will be updated!

3️⃣ SQL DELETE – Removing Records

The DELETE statement removes rows from a table. Use it carefully.

Delete a Single Record

DELETE FROM Employees
WHERE EmpID = 101;

Delete All Records (But Keep Table)

DELETE FROM Employees;

Completely Empty a Table (Faster)

TRUNCATE TABLE Employees;
Tip: TRUNCATE is faster than DELETE for removing all rows, but it cannot be rolled back in some databases.

✅ Key Takeaways

  • INSERT → Add new rows to a table
  • UPDATE → Modify existing rows
  • DELETE → Remove rows from a table
  • Always use WHERE with UPDATE and DELETE to avoid accidental changes
  • Use TRUNCATE when you need to quickly empty a table

📚 Continue Learning

💬 Got a question about SQL INSERT, UPDATE, DELETE? Drop it in the comments below and let’s discuss!




Leave a Comment