SQLITE bulk UPDATE statement

I want to execute many SQL UPDATE statements like these:

UPDATE cityd SET time_zone='-7.000000' WHERE locId = 173567; UPDATE cityd SET time_zone='-8.000000' WHERE locId = 173568; UPDATE cityd SET time_zone='-6.000000' WHERE locId = 173569; UPDATE cityd SET time_zone='-5.000000' WHERE locId = 173570; UPDATE cityd SET time_zone='-6.000000' WHERE locId = 173571; 

I want to optimize transaction time, so I need to use a BEGIN TRANSACTION / COMMIT pair. How to write this in SQL syntax in SQLtite Manager?

Edit: When I use the standard syntax in SQLite Manager, I get this error message: "SQLiteManager: BEGIN TRANSACTION; [cannot start a transaction within a transaction"

+4
source share
2 answers

According to SQL Documention , there are two supported CASE syntax

 CASE x WHEN w1 THEN r1 WHEN w2 THEN r2 ELSE r3 END CASE WHEN x = w1 THEN r1 WHEN x = w2 THEN r2 ELSE r3 END 

This way your multiple UPDATE can be further simplified to

 UPDATE cityd SET time_zone = CASE locId WHEN 173567 THEN '-7.000000' WHEN 173568 THEN '-8.000000' WHEN 173569 THEN '-6.000000' WHEN 173570 THEN '-5.000000' WHEN 173571 THEN '-6.000000' END WHERE locId IN (173567, 173568, 173569, 173570, 173571) 
+9
source
 BEGIN TRANSACTION; .....YOUR SQL Statements here COMMIT; 
0
source

All Articles