Need a good method to change SQLite column data type

I have a table with an 'int' column. During a software update, I want to change it to a "long" data type. It seems that SQLite does not provide an option (in the alter statement) for modifying / modifying column properties. Since I want to perform an update, the table may contain data that the user should not lose. Therefore, please offer me a good way to change the data type property of a column without losing data.

One way suggested in the search links is to create a temporary table, copy the records from the existing table, delete the existing table, and rename the temporary table. I doubt it is effective.

Your help was appreciated!

Hi

Vivek Ragunathan

+5
source share
5 answers

I used the following instructions to change the type of a column.

CREATE TABLE IF NOT EXISTS **TEMP_TABLE** (id integer primary key autoincrement, **col2change integer not null**, ...)

INSERT INTO TEMP_TABLE SELECT * FROM EXISTING_TABLE

DROP TABLE EXISTING_TABLE

ALTER TABLE TEMP_TABLE RENAME TO EXISTING_TABLE

I changed the int column in the existing table to an integer. For a few hundred lines, this was fast enough.

+10
source

There are no data types in SQLite3 columns, only affinities - there is no use in changing the column type from int to long.

- SQLite3, , . , . sqlite_master; , , writable_schema . , ; int long int, INTEGER.

+3

SQLite

, .

, SQLite.

Edit: , , - - , .

+1

colum, , ,

0

AFAIK Android . , ,

0

All Articles