Rename column in SQLite database table
In a SQLite database, modifying table columns is not a simple process. Although the ALTER TABLE statement exists, it cannot be used to rename columns in SQLite versions prior to 3.25.0.
Therefore, it is recommended to use the following generic SQL method to rename columns:
Create a temporary table with the required column names.
<code class="language-sql"> CREATE TABLE tmp_table_name ( col_a INT, col_b INT );</code>
Copy data from original table to temporary table.
<code class="language-sql"> INSERT INTO tmp_table_name(col_a, col_b) SELECT col_a, colb FROM orig_table_name;</code>
Delete the original table.
<code class="language-sql"> DROP TABLE orig_table_name;</code>
Rename the temporary table to the original table name.
<code class="language-sql"> ALTER TABLE tmp_table_name RENAME TO orig_table_name;</code>
Note: For SQLite 3.25.0 and later, you can use the simplified ALTER TABLE syntax to rename columns.
The above is the detailed content of How Do I Rename Columns in an SQLite Database Table?. For more information, please follow other related articles on the PHP Chinese website!