Open In App

SQLite Update Statement

SQLite is a database engine. It is a software that allows users to interact with relational databases, Basically, it is a serverless database which means it does not require any server to process queries. With the help of SQLite, we can develop embedded software without any configurations. SQLite is preferable for small datasets.

Update Statement

Sometimes it happens that we have inserted wrong data into our table by mistake so, how do we correct it? , No need to take pressure we can solve this problem by using UPDATE Command. Basically, it is a DML (Data Manipulation Language) command that is used to update the existing data from a table. With the help of the UPDATE Statement, we can update the data including single, or multiple rows. We will understand everything with the help of examples.



Syntax:

UPDATE table_name SET newdata WHERE condition


Update With Single-Field

We have an Employee table and we have to change Anshul’s city name from Varanasi to Agra. Here we need to change single data only with the UPDATE statement.



Employees Table

UPDATE Employees SET city = 'Agra' WHERE empName='Anshul'


Explanation: In this above query our new data is Agra so we put into the SET section and old data need to change comes into the WHERE clause as a condition. After Changement the our table look like.

After Changement of city name

Update With Multiple Field

Suppose in this Employees Table their is a new employee going to join the organization in place of Vaibhav who lives in the Meerut City and we need to change it to the new employee name along with thier city name, So here we have to change ,multiple data so here we use UPDATE Satatement.

Before Changes our table look like.

UPDATE Employees SET cempName='Neeraj',city = 'Pune' WHERE id=6


Explanation: In this above query we need to change the old employee name vaibhav to new employee name Neeraj along with old city Meerut to new city Pune.

After changement of employee and city name

Conclusion

UPDATE Statement is used to update the existing data from table. With the help of UPDATE Statement we can update either single data or multiple data in same queries. It is most frequently DML commands.

SQLite Update Statement – FAQs

1. What is UPDATE Statement ?

UPDATE Statement is a DML Command that we use to change or update the existing data from table.

2. Syntax for UPDATE Statement ?

UPDATE table_name SET new_data WHERE condition

3. Can we update single or multiple data ?

Yes, we can change either single or multiple data with same command in single line.

4. Is ALTER and UPDATE the same?

No, both are different ALTER is a DDL(Data Definition Language) commands and UPDATE is DML commands. ALTER is use to change the table structure while UPDATE is used to change the table data. you can learn in ALTER vs UPDATE commands.

Article Tags :