Paramclasses Academy - Blog

Tutorials Details

←
Post 11 of 40
→

SQL Server INSERT, UPDATE and DELETE Statements for Beginners: Complete Tutorial with Examples

SQL Server INSERT, UPDATE and DELETE Statements for Beginners: Complete Tutorial with Examples

November 16, 2026

SQL Server INSERT, UPDATE and DELETE Statements for Beginners: Complete Tutorial with Examples

✨ Introduction

In Microsoft SQL Server, managing data is one of the most important tasks in database development. After creating a database and tables, the next step is to insert new records, modify existing information, and delete unwanted records.

SQL Server provides three important Data Manipulation Language (DML) statements for performing these operations:

  • INSERT – Adds new records into a table.

  • UPDATE – Modifies existing records in a table.

  • DELETE – Removes records from a table.

Imagine that you are developing a Student Management System for a college. You need to add new student details, update student contact information, modify course fees, and delete student records when required.

For example:

  • When a new student takes admission, use INSERT.

  • When a student changes their mobile number, use UPDATE.

  • When an incorrect student record must be removed, use DELETE.

In this beginner-friendly SQL Server tutorial, we will understand these three important SQL statements with practical examples, syntax, output tables, common mistakes, and a real-world Student Management Database project.

???? 1. What Are INSERT, UPDATE and DELETE Statements?

INSERT, UPDATE, and DELETE are SQL Data Manipulation Language (DML) statements used to manage records stored inside database tables.

Each statement performs a different operation.

SQL Statement Purpose Example
INSERT Adds new records Add a new student
UPDATE Modifies existing records Change student fees
DELETE Removes existing records Delete a student

These statements are commonly used in database-driven applications such as:

  • Student Management Systems

  • Employee Management Systems

  • Hospital Management Systems

  • Inventory Management Systems

  • Banking Applications

  • E-commerce Websites

???? 2. Understanding the INSERT Statement

The INSERT statement is used to add new records into an existing SQL Server table.

Whenever a new student, employee, customer, or product is added to a database, the INSERT statement can be used.

A. INSERT Statement Syntax

INSERT INTO table_name
(
    column1,
    column2,
    column3
)
VALUES
(
    value1,
    value2,
    value3
);

Explanation:

  • INSERT INTO specifies the target table.

  • Column names identify where the data will be stored.

  • VALUES provides the actual data to insert.

B. Create a Student Table

First, create a table to store student information.

CREATE TABLE Students
(
    StudentID INT PRIMARY KEY,
    StudentName VARCHAR(100),
    City VARCHAR(50),
    Course VARCHAR(100),
    Fees DECIMAL(10,2)
);

This table contains five columns:

Column Data Type Purpose
StudentID INT Student identification
StudentName VARCHAR(100) Student name
City VARCHAR(50) Student city
Course VARCHAR(100) Course name
Fees DECIMAL(10,2) Course fees

C. Insert a Single Record

Now insert one student record into the Students table.

INSERT INTO Students
(
    StudentID,
    StudentName,
    City,
    Course,
    Fees
)
VALUES
(
    101,
    'Rahul Sharma',
    'Raipur',
    'SQL Server',
    15999.50
);

Output:

StudentID StudentName City Course Fees
101 Rahul Sharma Raipur SQL Server 15999.50

The INSERT statement adds one new student record to the Students table.

D. Insert Multiple Records

SQL Server also allows multiple records to be inserted using a single INSERT statement.

Example:

INSERT INTO Students
(
    StudentID,
    StudentName,
    City,
    Course,
    Fees
)
VALUES
(102, 'Amit Verma', 'Durg', 'Python', 12500.00),
(103, 'Priya Singh', 'Bilaspur', 'Web Development', 18000.00),
(104, 'Neha Patel', 'Raipur', 'Java', 15000.00),
(105, 'Rohit Kumar', 'Bhilai', 'SQL Server', 15999.50);

Output:

StudentID StudentName City Course Fees
102 Amit Verma Durg Python 12500.00
103 Priya Singh Bilaspur Web Development 18000.00
104 Neha Patel Raipur Java 15000.00
105 Rohit Kumar Bhilai SQL Server 15999.50

Important: Multiple-row INSERT statements using VALUES are supported in SQL Server. The table's constraints and data types must be satisfied by every inserted record.

E. INSERT Without Specifying All Columns

You can also insert values into selected columns if the remaining columns allow NULL, have a DEFAULT value, or are automatically generated.

Example:

INSERT INTO Students
(
    StudentID,
    StudentName,
    City
)
VALUES
(
    106,
    'Ankit Sharma',
    'Raipur'
);

In this example, Course and Fees are not specified. Since they allow NULL, SQL Server stores NULL in those columns.

F. INSERT Using DEFAULT VALUES

If a table contains columns with default constraints, you can use DEFAULT VALUES to insert a record using those default values.

Example:

CREATE TABLE StudentStatus
(
    StatusID INT IDENTITY(1,1),
    StatusName VARCHAR(50)
        DEFAULT 'Active'
);

Insert a record:

INSERT INTO StudentStatus
DEFAULT VALUES;

Check the result:

SELECT * FROM StudentStatus;

The default StatusName will be Active.

???? 3. Understanding the UPDATE Statement

The UPDATE statement is used to modify existing records in a SQL Server table.

For example, if a student changes their city, phone number, course, or fees, the UPDATE statement can modify that information without creating a new record.

A. UPDATE Statement Syntax

UPDATE table_name
SET column1 = value1,
    column2 = value2
WHERE condition;

Explanation:

  • UPDATE specifies the table to modify.

  • SET specifies the new column values.

  • WHERE identifies the records that need to be updated.

B. Update a Single Record

Suppose Rahul Sharma has moved from Raipur to Durg.

We want to update his city.

UPDATE Students
SET City = 'Durg'
WHERE StudentID = 101;

Check the updated record:

SELECT * FROM Students
WHERE StudentID = 101;

Output:

StudentID StudentName City Course Fees
101 Rahul Sharma Durg SQL Server 15999.50

The city of Rahul Sharma has been changed from Raipur to Durg.

C. Update Multiple Columns

You can modify multiple columns in a single UPDATE statement.

Example:

UPDATE Students
SET
    City = 'Bilaspur',
    Course = 'Python',
    Fees = 14000.00
WHERE StudentID = 102;

Check the result:

SELECT * FROM Students
WHERE StudentID = 102;

Output:

StudentID StudentName City Course Fees
102 Amit Verma Bilaspur Python 14000.00

D. Update Records Using Conditions

You can also update records based on a condition.

Example:

Suppose you want to increase the course fees of all students enrolled in SQL Server.

UPDATE Students
SET Fees = Fees + 1000
WHERE Course = 'SQL Server';

This query increases the fees by 1000 for every student enrolled in SQL Server.

E. Update All Records Without WHERE

You can execute UPDATE without a WHERE condition.

Example:

UPDATE Students
SET City = 'Raipur';

This statement updates the City column for every record in the Students table.

Warning: Always check your WHERE condition before executing an UPDATE statement. Without WHERE, all rows are affected.

???? 4. Understanding the DELETE Statement

The DELETE statement is used to remove existing records from a SQL Server table.

For example, if a student record was entered incorrectly or a record needs to be removed according to business requirements, DELETE can be used.

A. DELETE Statement Syntax

DELETE FROM table_name
WHERE condition;

Explanation:

  • DELETE FROM specifies the target table.

  • WHERE identifies which records should be removed.

B. Delete a Single Record

Suppose we want to delete the student whose StudentID is 105.

DELETE FROM Students
WHERE StudentID = 105;

Check the remaining records:

SELECT * FROM Students;

The student record with StudentID 105 will no longer appear in the table.

C. Delete Multiple Records Using Conditions

You can delete multiple records by specifying a suitable condition.

Example:

DELETE FROM Students
WHERE City = 'Durg';

This statement deletes all student records whose city is Durg.

D. Delete All Records From a Table

You can delete all records without using a WHERE condition.

DELETE FROM Students;

Important: This removes all rows from the table but does not remove the table structure.

The table and its columns remain available.

Warning: Before executing DELETE without WHERE, verify that removing every record is actually intended.

???? 5. Difference Between INSERT, UPDATE and DELETE

These three statements are used for different data management operations.

Feature INSERT UPDATE DELETE
Purpose Adds records Modifies records Removes records
Existing Record Required No Yes Yes
WHERE Clause Not normally used Optional Optional
Table Structure Remains unchanged Remains unchanged Remains unchanged
Main Operation Add Modify Remove

???? 6. Difference Between DELETE and TRUNCATE

DELETE and TRUNCATE are both used to remove table data, but their behavior is different.

Feature DELETE TRUNCATE
Removes Records Yes Yes
WHERE Condition Supported Not supported
Removes Selected Rows Yes No
Identity Counter Usually continues Resets to seed
Table Structure Remains Remains
Logging Logs row deletions Uses page deallocation logging
Foreign Key Restrictions Subject to constraints Cannot truncate a table referenced by a foreign key

DELETE Example

DELETE FROM Students
WHERE StudentID = 101;

This removes only the specified student.

TRUNCATE Example

TRUNCATE TABLE Students;

This removes all rows from the table.

Important: TRUNCATE is a separate DDL statement in SQL Server. It does not support WHERE and cannot be used when another table references the target table through a foreign key.

???? 7. INSERT Using SELECT Statement

SQL Server also allows data to be inserted into one table using records retrieved from another table.

This is useful when transferring or copying records between tables.

Step 1: Create an Archive Table

CREATE TABLE StudentsArchive
(
    StudentID INT,
    StudentName VARCHAR(100),
    City VARCHAR(50),
    Course VARCHAR(100),
    Fees DECIMAL(10,2)
);

Step 2: Insert Data Using SELECT

INSERT INTO StudentsArchive
(
    StudentID,
    StudentName,
    City,
    Course,
    Fees
)
SELECT
    StudentID,
    StudentName,
    City,
    Course,
    Fees
FROM Students
WHERE City = 'Raipur';

Step 3: Check the Archive Table

SELECT * FROM StudentsArchive;

This query copies the matching student records from Students into StudentsArchive.

???? 8. Using Transactions With UPDATE and DELETE

Transactions help manage database operations as a unit of work.

SQL Server supports transaction commands such as:

  • BEGIN TRANSACTION

  • COMMIT TRANSACTION

  • ROLLBACK TRANSACTION

Example: UPDATE With Transaction

BEGIN TRANSACTION;

UPDATE Students
SET Fees = 17000
WHERE StudentID = 101;

SELECT * FROM Students
WHERE StudentID = 101;

COMMIT TRANSACTION;

COMMIT saves the transaction changes.

Example: DELETE With ROLLBACK

BEGIN TRANSACTION;

DELETE FROM Students
WHERE StudentID = 104;

SELECT * FROM Students;

ROLLBACK TRANSACTION;

ROLLBACK reverses the uncommitted transaction changes.

Important: ROLLBACK can reverse the DELETE operation here because the deletion is inside an active transaction and has not been committed.

???? 9. Practical Example: Student Management Database

Now let's create a complete practical example using INSERT, UPDATE, and DELETE statements.

Step 1: Create a Database

CREATE DATABASE StudentDB;
GO

Step 2: Select the Database

USE StudentDB;
GO

Step 3: Create a Students Table

CREATE TABLE Students
(
    StudentID INT PRIMARY KEY,
    StudentName VARCHAR(100),
    City VARCHAR(50),
    Course VARCHAR(100),
    Fees DECIMAL(10,2)
);

Step 4: Insert Student Records

INSERT INTO Students
(
    StudentID,
    StudentName,
    City,
    Course,
    Fees
)
VALUES
(101, 'Rahul Sharma', 'Raipur', 'SQL Server', 15999.50),
(102, 'Amit Verma', 'Durg', 'Python', 12500.00),
(103, 'Priya Singh', 'Bilaspur', 'Web Development', 18000.00),
(104, 'Neha Patel', 'Raipur', 'Java', 15000.00),
(105, 'Rohit Kumar', 'Bhilai', 'SQL Server', 15999.50);

Step 5: Display All Students

SELECT * FROM Students;

Step 6: Update Student Information

UPDATE Students
SET
    City = 'Durg',
    Course = 'SQL Server',
    Fees = 17000.00
WHERE StudentID = 103;

Step 7: Verify Updated Records

SELECT * FROM Students
WHERE StudentID = 103;

Step 8: Delete a Student Record

DELETE FROM Students
WHERE StudentID = 105;

Step 9: Display Final Records

SELECT * FROM Students;

Final Output

StudentID StudentName City Course Fees
101 Rahul Sharma Raipur SQL Server 15999.50
102 Amit Verma Durg Python 12500.00
103 Priya Singh Durg SQL Server 17000.00
104 Neha Patel Raipur Java 15000.00

Through this practical project, you have learned how to insert new student records, update existing student information, and delete unwanted records using SQL Server.

???? 10. Common Mistakes While Using INSERT, UPDATE and DELETE

Beginners often make mistakes when working with SQL data manipulation statements.

1. Missing Required Column Values

If a column has a NOT NULL constraint and no default value, omitting it can cause an insertion error.

Solution: Provide a valid value for every required column.

2. Duplicate Primary Key

Inserting a record with an existing primary key causes a primary key violation.

Solution: Always use a unique StudentID.

3. Incorrect Data Types

Inserting text into an integer column or an invalid value into a date column can cause conversion errors.

Solution: Match values with the correct column data types.

4. Forgetting the WHERE Clause in UPDATE

Without WHERE, UPDATE modifies every row.

Solution: Always verify the condition before executing the query.

5. Forgetting the WHERE Clause in DELETE

Without WHERE, DELETE removes all records from the table.

Solution: Check the target records using SELECT before deleting them.

6. Deleting Records Referenced by Foreign Keys

A DELETE operation may fail when another table references the record through a foreign key.

Solution: Understand table relationships and referential constraints before deleting records.

???? 11. Best Practices for INSERT, UPDATE and DELETE

  1. Always specify column names in INSERT statements.

  2. Use appropriate data types for inserted values.

  3. Check existing records before updating them.

  4. Use specific WHERE conditions for UPDATE and DELETE.

  5. Use transactions for important database changes.

  6. Take database backups before performing large-scale modifications.

  7. Verify the affected rows after executing a query.

  8. Avoid deleting important production records without proper authorization.

  9. Test queries in a development environment before applying them to production.

???? 12. Frequently Asked Questions (FAQs)

Q1. What is the INSERT statement in SQL Server?

INSERT is used to add new records into an existing SQL Server table.

Q2. What is the UPDATE statement in SQL Server?

UPDATE is used to modify existing records in a database table.

Q3. What is the DELETE statement in SQL Server?

DELETE removes selected records or all records from a table, depending on the WHERE condition.

Q4. Can we insert multiple records using one INSERT statement?

Yes. SQL Server supports inserting multiple rows using a single INSERT INTO statement with multiple VALUES clauses.

Q5. What happens if we use UPDATE without WHERE?

All records in the specified table are updated.

Q6. What happens if we use DELETE without WHERE?

All records in the specified table are deleted, but the table structure remains.

Q7. What is the difference between DELETE and TRUNCATE?

DELETE can remove selected rows using WHERE, whereas TRUNCATE removes all rows and does not support WHERE.

Q8. Can we recover deleted records using ROLLBACK?

Yes, if the DELETE operation is performed inside an active transaction and has not been committed.

Q9. Can INSERT be used to copy data from another table?

Yes. INSERT INTO SELECT can retrieve records from one table and insert them into another table.

Q10. Which SQL statements are used to manage table records?

INSERT, UPDATE, and DELETE are commonly used to add, modify, and remove table records.

???? Conclusion

INSERT, UPDATE, and DELETE are three essential SQL Server statements used for managing records in relational databases. They allow developers to add new information, modify existing records, and remove unwanted data.

In this tutorial, we learned the INSERT statement for adding single and multiple records, the UPDATE statement for modifying one or more columns, and the DELETE statement for removing selected or all records.

We also explored the differences between DELETE and TRUNCATE, INSERT INTO SELECT, transaction management using COMMIT and ROLLBACK, and a practical Student Management Database project.

At Param Classes, we focus on helping students and beginners learn SQL Server through simple explanations, practical SQL queries, and real-world database projects. Keep practising these statements to build strong database management skills and move forward toward professional SQL Server development.

???? Learn. Practice. Build with Param Classes!

←
Post 11 of 40
→