SQLite – alter a table’s column type?

SQLite does not fully support ALTER TABLE statements. The only thing you can do is rename a table and/or add columns. If you want to rename a column, your best option is to create a new table with the new columns datatype/names, and to drop the old table in order to rename the new one.

Lets say, you have a table and need to rename “field-1” to “field-2”:
First ==>> rename the old table:

    ALTER TABLE original RENAME TO tmp;

Now create the new table based on the old table but with the updated column name:
==>> create a table with the updated columns

    CREATE TABLE original(
    field_a INT
   , field_b INT
    );

Then copy the contents across from the original table.

   INSERT INTO origignal(field_a, field_b)
   SELECT field_a, field_b
   FROM tmp;

Lastly, drop the old table.

   DROP TABLE tmp;

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)