How to delete, modify, and rename a column bitsCN.com in SQLite
Today, I added a column to the SQLite database. later I found that the column name was wrong. so I used an SQL statement to modify the column name, but it didn't work.
First, discard alter.
Sqlite official instructions are as follows:
SQLite supports a limited subset of alter table. the alter table command in SQLite allows the user to rename a table or to add a new column to an existing table. it is not possible to rename a column, remove a column, or add or remove constraints from a table.
The alter function of sqlite is only a subset of alter table. only some functions are available, such as renaming a table name and adding columns to an existing table.
You cannot rename, delete, or modify an existing column.
After checking N more data, it seems that only one indirect method can be used, whether it is to rename or delete a column.
For example, if the name of the table to be modified is A, follow these steps:
1. create A temporary table T, which has the same columns as Table.
2. insert all data in A Into T using the insert statement.
3. delete Table
4. when creating Table A, the column name of Table A is the result you want. what is the column name you want to modify before? what is this time? A column to be deleted previously, so it is not defined when it is defined.
5. restore data and insert data into A using the insert statement. The structure is insert into A select... from tablen T.
6. delete temporary table T.
This method is too clumsy, but there is no better way yet,
BitsCN.com