您的位置:首页 > 数据库

sqlite rename column name

2013-10-24 13:51 357 查看
Say you have a table and need to rename "colb" to "col_b":

First you rename the old table:
ALTER TABLE orig_table_name RENAME TO tmp_table_name;


Then create the new table, based on the old table but with the updated column name:
CREATE TABLE orig_table_name (
col_a INT
, col_b INT
);


Then copy the contents across from the original table.
INSERT INTO orig_table_name(col_a, col_b)
SELECT col_a, colb
FROM tmp_table_name;


Lastly, drop the old table.
DROP TABLE tmp_table_name;


Wrapping all this in a
BEGIN
TRANSACTION;
and
COMMIT;
is
also probably a good idea.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐