0

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??

Community
  • 1
  • 1

1 Answers1

2

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

PA.
  • 28,486
  • 9
  • 71
  • 95
  • ok .. but i have to calculate the length of time to do that when the table contains 1000 row...and thanks for the suggestion.... – Ricky Robert Oct 02 '12 at 07:03