General Note: Here we have pulled in the data from a sample database. You can download it from the following link and use it for practicing Click Here For Sample Database

In this tutorial, you will learn how to use the update keyword in SQLite .Update keyword is used to update already existing data in the column or used to correct the mistaken values. Update is most widely used keyword. Every day lot of data is updated. Say for example, In banking every day customer account is updated with debit or credit.

Syntax:


UPDATE table_name

SET column1 = value1[, column2 = value2,....] [WHERE condition];

We can update one column or more than one column at a time. Here where condition is mentioned as optional.

However, in practical, where is more mandatory. If you are not using where condition all the record of column updated.

So it will cause serious problem. Before updating am going to take a copy of some table and will update the data.

 
Create table sample as select mobile_name,price,sold_count,os_name
 from mobile_sales_details

We partially copied some data from the mobile sales table. We did not want to change the source data that is why we took the copy of table. Then now going to update the Google’s Moto E sold count to 500.

So you must write where condition

 
Update sample set sold_count=500 where mobile_name=’Moto E (Black)’

In the above query, If you skip the condition all the mobiles sold count will be updated to 500. So be careful while updating data.

If you want to update multiple column at a time use the below query.

 
Update sample set sold_count=500, price =15000 where mobile_name=’Moto E (Black)’

Here Moto E‘s sold count and price only updated. And the below query will update all mobiles sold count and price to 500, 15000.

 
Update sample set sold_count=500, price =15000

So the best advice is be careful with update keyword while you working with live database.

However, always take a backup copy before updating data. That will save you from hectic work