UPDATE syntax in SQLite

I need to know if I can do this in an UPDATE statement:

UPDATE users SET ('field1', 'field2', 'field3') 
VALUES ('value1', 'value2', 'value3');

Or similar syntax. I'm using SQLite.

Note:

Nobody understands me, I just want to know if it is possible to SET separate fields to separate values. That's all.

There is a (standard SQL) syntax that is similar to what you propose but as far as I know, only Postgres has implemented it:

UPDATE users
SET  (field1, field2, field3)
   = ('value1', 'value2', 'value3') 
WHERE some_condition ;

Tested (for the infidels) in: SQL-Fiddle


This also works in Postgres:

UPDATE users AS u
SET 
   (field1, field2, field3)
 = (f1, f2, f3)
FROM
  ( VALUES ('value1', 'value2', 'value3')
  ) AS  x (f1, f2, f3)
WHERE condition ;

This works in Postgres and SQL-Server:

UPDATE users 
SET 
   field1 = f1, field2 = f2, field3 = f3
FROM
  ( VALUES ('value1', 'value2', 'value3')
  ) AS  x (f1, f2, f3)
WHERE condition ;

and as @JackDouglas commented, this works in Oracle:

UPDATE users
SET  (field1, field2, field3)
   = ( SELECT 'value1', 'value2', 'value3' FROM dual ) 
WHERE condition ;

update, hide. syntax diagram update-stmt If the UPDATE statement does not have a WHERE clause, all rows in the table are modified by the UPDATE. Otherwise, the � In this syntax: 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. If you skip it, the Finally, use the

What you posted is not the correct syntax for UPDATE. To UPDATE your syntax is:

UPDATE users 
SET field1 = 'value1',
    field2 = 'value2',
    field3 =  'value3';

You will want to add a WHERE clause or this will UPDATE all records.

SQLite - UPDATE Query, SQLite UPDATE Query is used to modify the existing records in a table. You can Syntax. Following is the basic syntax of UPDATE query with WHERE clause. UPDATE inventory SET quantity = quantity - daily.amt FROM (SELECT sum(quantity) AS amt, itemId FROM sales GROUP BY 2) AS daily WHERE inventory.itemId = daily.itemId; The subquery in the FROM clause computes the amount by which theinventory should be reduced for each itemId. That subquery is joinedagainst the inventory table and the quantity of each affected inventoryrow is reduced by the appropriate amount.

If you want to update a record, it should look like this. You should very rarely want to update without a WHERE condition.

UPDATE users
SET field1='value1',
    field2='value2',
    field3='value3'
WHERE field1=1

SQL Fiddle

SQLite Update Statement, The data modification clauses in SQLite are INSERT, UPDATE, and DELETE statements. The following is the syntax of the UPDATE clause:. SQLite UPDATE Query is used to modifying the existing records in a table. You can use WHERE clause with UPDATE query to update selected rows. The UPDATE clause updates a table by changing a value for a specific column. The following is the syntax of the UPDATE clause:

Try

UPDATE users SET field1='value1', field2='value2'

etc...

You can find the official docs here.

W3Schools also has a useful page:

SQL UPDATE Statement

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

SQL UPDATE Syntax

UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value

Note: Notice the WHERE clause in the UPDATE syntax. The WHERE clause specifies which record or records that should be updated. If you omit the WHERE clause, all records will be updated!

EDIT: since you seem to need to create a string, the normal method to do so safely is to use prepared statements.

Assuming Java, we already have this example on StackOverflow:

SQLiteDatabase db = dbHelper.getWritableDatabase();
SQLiteStatement stmt = db.compileStatement("SELECT * FROM Country WHERE code = ?");
stmt.bindString(1, "US");
stmt.execute();

In your case,

SQLiteDatabase db = dbHelper.getWritableDatabase();
SQLiteStatement stmt = db.compileStatement("UPDATE users SET field1=?, field2=?...");
stmt.bindString(1, "value1");
stmt.bindString(2, "value2");
stmt.execute();

SQLite INSERT, UPDATE, DELETE Query with Example, This SQLite tutorial explains how to use the SQLite UPDATE statement with syntax and examples. The SQLite UPDATE statement is used to update existing� The UPDATE statement in SQLite allows us to easily update several columns through short queries. In this example, the SQLite UPDATE statement updates two columns (STATUS to “Repaired” and “QUANTITY” to 4) in our Phones table, where the PHONE_ID is equal to 1. The syntax we will be using is as follows:

No, there is no such syntax in sqlite (postgress seems to have such thing implemented) - but better use:

UPDATE users SET firstname = 'Joe', lastname = 'value2', age = 50 WHERE id=12;

SQLite: UPDATE Statement, There is a (standard SQL) syntax that is similar to what you propose but as far as I know, only Postgres has implemented it: UPDATE users SET� update demo set name = 'SqLITE' where id = 1. update demo set name=case. when id=2 then 'text 2'. when id=3 then 'text 3'. end where id in (2,3); -- multi update in one request. MariaDB. UPDATE [ LOW_PRIORITY] [ IGNORE] table_reference.

UPDATE syntax in SQLite, It is used with WHERE clause to select the specific row otherwise all the rows would be updated. Syntax: UPDATE table_name; SET column1 = value1, column2� SQL UPDATE Statement. The UPDATE statement is used to update records in a table. SQL UPDATE Syntax. UPDATE table_name SET column1=value, column2=value2, WHERE some_column=some_value Note: Notice the WHERE clause in the UPDATE syntax. The WHERE clause specifies which record or records that should be updated.

SQLite Update Query, This command can update more than one rows at a time, but all of the rows must be part of the same table. Syntax: UPDATE table_name SET� SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC, ODBC etc. This example demonstrate about How to use update command in Android sqlite.

SQLite UPDATE, Use Python sqlite3 module to update SQLite table. Update single row, multiple rows, single column and multiple columns of a SQLite table from� UPDATE Syntax. UPDATE table_name. SET column1 = value1, column2 = value2, WHERE condition; Note: Be careful when updating records in a table! Notice the WHERE clause in the UPDATE statement. The WHERE clause specifies which record (s) that should be updated.

Comments
  • Doesn't MySQL have tuples and Oracle sets?
  • @Richard: I think this doesn't work in MYSQL. In a condition it works: WHERE (a,b) = (c,d) though...
  • Beginning in SQLite version 3.15.0 (2016-10-14), an assignment in the SET clause can be a parenthesized list of column names on the left and a row value of the same size on the right. So, yes, the syntax is valid.
  • Stealing "for the infidels" :joy:
  • Did you read the question? I'm actually asking if there's a syntax like that because I know what's the correct one.
  • This is not the answer for this question.
  • No, I need create a string and this sintax isn't useful to me. :(
  • @calbertts if you need to "create a string" then you need to rephrase/rethink your question. as it stands, the three answers here all satisfy your question.
  • NO! nobody understands me, I just want to know if is possible separate fields of the values.. thats all..