Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing a value in SQLite3

I'll start off by showing the code:

create table products ('name' text primary key, 'price' INTEGER)
insert into table products ('name', 'price') values ('coke', 8)
insert into table products ('name', 'price') values ('sprite', 9)

What would be the SQLite3 code to change the value of the price column for the coke row to 12.
So I want the output to be coke 12 sprite 9.

Thanks alot guys!

like image 733
james Avatar asked Jan 13 '11 23:01

james


People also ask

How do I change the value of a column in SQLite?

Introduction to SQLite UPDATE statement First, specify the table where you want to update after the UPDATE clause. Second, set new value for each column of the table in the SET clause. Third, specify rows to update using a condition in the WHERE clause. The WHERE clause is optional.

How do I edit a SQLite table?

Summary. Use the ALTER TABLE statement to modify the structure of an existing table. Use ALTER TABLE table_name RENAME TO new_name statement to rename a table. Use ALTER TABLE table_name ADD COLUMN column_definition statement to add a column to a table.

Which SQLite statement is used to update data into table?

The SQLite UPDATE statement is used to update existing records in a table in a SQLite database.


1 Answers

UPDATE products 
   SET price = 12 
 WHERE name = 'coke' AND price = 8;

These might just be transcription errors or typos, but you should remove the word table from your INSERT statements, and you don't need single-quotes around column names, so the statement should look like:

insert into products (name, price) values ('sprite', 9)
like image 179
mechanical_meat Avatar answered Sep 18 '22 11:09

mechanical_meat