INSERT, UPDATE, and DELETE in SQL Server for Beginners
After creating a table, you need to add, change, and remove rows. SQL Server provides INSERT, UPDATE, and DELETE for these operations.
INSERT a Row
INSERT INTO Students (StudentName, Age, EnrollmentDate)
VALUES ('Anita', 21, '2026-08-28');
Listing the target columns explicitly makes the statement easier to read and safer when the table structure changes.
INSERT Multiple Rows
INSERT INTO Students (StudentName, Age)
VALUES
('Rahul', 20),
('Meena', 22),
('Arun', 19);
UPDATE a Row
UPDATE Students
SET Age = 23
WHERE StudentName = 'Meena';
The WHERE clause limits which rows are changed.
Why WHERE Matters
Be careful with an UPDATE without a WHERE clause:
UPDATE Students
SET Age = 25;
This changes every row in the table. In production, verify the rows selected by your condition before executing a data-changing statement.
DELETE a Row
DELETE FROM Students
WHERE StudentName = 'Arun';
As with UPDATE, the WHERE clause is critical when you intend to remove only selected rows.
Check Before Changing Data
SELECT *
FROM Students
WHERE StudentName = 'Meena';
Previewing the matching rows before an UPDATE or DELETE is a simple habit that can prevent accidental changes.
Use a Transaction While Practicing
BEGIN TRANSACTION;
UPDATE Students
SET Age = Age + 1
WHERE Age < 21;
SELECT *
FROM Students;
-- COMMIT TRANSACTION;
-- ROLLBACK TRANSACTION;
While learning, you can test the result and then choose COMMIT to keep the changes or ROLLBACK to undo them.
What to Learn Next
Once you are comfortable changing rows, learn how to retrieve related data with SELECT, filtering, sorting, and joins.
Start with SQL SELECT, WHERE, and ORDER BY for Beginners or continue to the SQL Server Tutorials hub.
đŦ Comments
Sign in with Google to publish immediately, or comment anonymously and wait for approval.
Loading comments...