UPDATE Query in SQLite

SQLite UPDATE Query To modify the existing records in a table, the UPDATE query is used in SQLite.

Syntax:

UPDATE table_name  
SET column_1 = value_1, column_2 = value_2...., column_N = value_N  
WHERE conditions;   

Example 1: TEACHERS Table:

ID NAME SUBJECT
1 Jim English
2 John Geology
3 Watson French
4 Holmes Chemistry
5 Tony Physics

Example:

UPDATE TEACHERS 
SET SUBJECT = 'Spanish' WHERE ID = 3;

Explanation: Here we have updated the value of the SUBJECT column in an already existing table “TEACHERS” where ID is 3. To verify the table data execute the below query. SELECT * FROM TEACHERS;

Output:

ID NAME SUBJECT
1 Jim English
2 John Geology
3 Watson Spanish
4 Holmes Chemistry
5 Tony Physics

Example 2: TEACHERS Table:

ID NAME SUBJECT
1 Jim English
2 John Geology
3 Watson French
4 Holmes Chemistry
5 Tony Physics

Example:

UDATE TEACHERS 
SET SUBJECT = 'Spanish'

Explanation: Here we have updated the value of the SUBJECT column in an already existing table “TEACHERS” without using the WHERE clause. Thus all the subjects will be modified in the table. To verify the table data execute the below query. SELECT * FROM TEACHERS;

Output:

ID NAME SUBJECT
1 Jim Spanish
2 John Spanish
3 Watson Spanish
4 Holmes Spanish
5 Tony Spanish
Please follow and like us:
Content Protection by DMCA.com