SQLITE bulk UPDATE statement

sql, sqlite

Solution

According on SQL Documention, there are two supported syntax of `CASE`

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

So your multiple `UPDATE` statements can be further simplified into

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)

Problem

I want to perform 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 the transaction time, so I need to use 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 receive this error message: "SQLiteManager: BEGIN TRANSACTION; [ cannot start a transaction within a transaction "

Original source