0

I have some table in SQLite that has a column named Numbers. This table contains N elements. I want to create some kind of an update query that allows me to change Numbers' values for 1-N.

I wanted to add a new column that autoincrements (so it would be exactly as I want to). Then copy values from my temporary column to Numbers (I don't want to rename it to avoid dealing with constraints). Then drop the temp column. But... The problem is SQLite doesn't support anything like RENAME COLUMN/DELETE COLUMN for ALTER TABLE.

How can I update my column in such a way?

4

1 回答 1

1
  1. 创建临时表;
  2. 使用主键(ROWID如果没有则使用)和新的计算填充它Numbers
  3. UPDATE your_table SET Numbers=(SELECT Numbers FROM temp_table WHERE id=your_table.id) WHERE id IN (SELECT id FROM temp_table)
  4. 删除临时表。
于 2013-10-21T09:15:54.577 回答