When you work with databases, data rarely stays the same forever. User details change, prices increase, and statuses get updated. This is where the UPDATE query in SQL becomes important.

    The UPDATE query allows you to change existing data in a table without deleting it. In this article, I’ll explain the UPDATE query in simple language with easy, practical examples that you can actually relate to.

    What Is an UPDATE Query in SQL?

    An UPDATE query in SQL is used to modify data that already exists in a table.
    Instead of adding new rows, it updates values inside existing rows.

    You usually use it when:

    • A user updates their profile
    • A product price changes
    • An employee’s salary increases
    • A record needs correction

    Basic Syntax of UPDATE Query in SQL

    UPDATE table_name
    
    SET column_name = new_value
    
    WHERE condition;

    The SET keyword defines what you want to change, and the WHERE clause tells SQL which rows to update.

    👉 Without WHERE, SQL updates every row in the table.

    Example Table: Students

    student_id name course marks
    1 Vijay Math 70
    2 Neha Science 85
    3 Aman Math 60

    Simple UPDATE Query Example

    Suppose Vijay’s marks were entered incorrectly, and you want to update them.

    UPDATE students
    
    SET marks = 75
    
    WHERE student_id = 1;

    This query updates only Vijay’s marks.
    All other records remain unchanged.

    Updating Multiple Columns at Once

    You can update more than one column in a single query.

    UPDATE students
    
    SET course = 'English', marks = 80
    
    WHERE name = 'Neha';

    SQL updates both the course and marks together.
    This saves time and keeps your query clean.

    UPDATE Query Without WHERE Clause

    UPDATE students
    
    SET marks = 90;

    ⚠️ This query updates marks for every student.

    Use this type of query only when you intentionally want to modify all records. Otherwise, it can cause serious data issues.

    UPDATE Query with Conditions

    You can use conditions to update multiple rows selectively.

    UPDATE students
    
    SET marks = marks + 5
    
    WHERE course = 'Math';

    This query increases marks by 5 for all Math students.

    Using Comparison Operators in UPDATE

    UPDATE students
    
    SET marks = 65
    
    WHERE marks < 65;

    SQL updates only those students who scored less than 65.

    Best Practice: Always Check Before Updating

    Before running an UPDATE query, first check which rows will be affected.

    SELECT * FROM students
    
    WHERE student_id = 3;

    Once you confirm the data, then run:

    UPDATE students
    
    SET marks = 70
    
    WHERE student_id = 3;

    This habit prevents accidental updates.

    Common Mistakes Beginners Make

    • Forgetting the WHERE clause
    • Updating the wrong column
    • Not checking affected rows
    • Running UPDATE directly on live data

    Avoiding these mistakes will save you from major problems.

    When Should You Use an UPDATE Query in SQL?

    Use the UPDATE query when you need to:

    • Fix incorrect data
    • Modify user or student details
    • Update prices, marks, or status values
    • Keep database records accurate

    Final Thoughts

    The UPDATE query in SQL is simple, powerful, and essential for working with real-world databases. If you use it carefully with proper conditions, it helps you maintain clean and accurate data.

    Read Also – SQL Union Operator

    Share.

    Vijay Chauhan is a tech professional with over 9 years of hands-on experience in web development, app design, and digital content creation. He holds a Master’s degree in Computer Science. At SchoolUnzip, Vijay shares practical guides, tutorials, and insights to help readers stay ahead in the fast-changing world of technology.

    Leave A Reply