Possible Duplicate:
How do I rename a column in a SQLite database table?
I want to rename field table in SQlite, but I can’t rename it in my aplication. This my query to rename:
ALTER TABLE 'table_name' RENAME 'column1' TO 'new_column1'
but my query gets this error:
SQLiteManager: Likely SQL syntax error: ALTER table 'table_name'
RENAME 'column1' TO 'new_column1' [ near "'column1'": syntax error ]
Exception Name: NS_ERROR_FAILURE
Exception Message: Component returned failure code: 0x80004005
(NS_ERROR_FAILURE) [mozIStorageConnection.createStatement]
and can’t rename field…
i change my query :
ALTER TABLE 'table_name' RENAME COLUMN 'column1' TO 'new_column1'
ALTER TABLE 'table_name' CHANGE 'column1' 'new_column1' TEXT
and error again…
how do I solve my problem??
You can’t directly rename a column in a SQLite table. You need to re-create the table. The overall process is this
1.- create a new table with the new column
2.- copy all the old table contents to the new table
3.- recreate all indexes
4.- rename the old table to another name
5.- rename the new table to the original name