[转帖]HOWTO rename column name in Sqlite3 database
2015-08-04 15:06
756 查看
原文在此
Say you have a table and need to rename "colb" to "col_b":
First you rename the old table:
Then create the new table, based on the old table but with the updated column name:
Then copy the contents across from the original table.
Lastly, drop the old table.
Wrapping all this in a
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.
相关文章推荐
- oracle Date format日期和月份不补0
- mysql数据库数据迁移方法
- 设定NFS恢复archive log dest在local disk的RAC 数据库
- mongodb操作
- 使用EF6连接MySQL
- Linux下php安装Redis扩展
- MySQL Study之--MySQL存储过程循环
- Oracle 用户、角色、权限(系统权限、对象权限)的数据字典表
- 查看已经执行过的sql的执行计划
- 利用mysql-proxy进行mysql数据库的读写分离
- oracle函数调用存储过程
- mysql表分区
- MongoDB常用命令
- SQLite常用语句
- mysql表修复问题---(table is marked as crashed and should be repaired)
- SQL try
- 深入解析Oracle学习笔记(第一章)
- Ubuntu下彻底卸载mysql
- 基于Redis的MessageQueue队列封装
- EF,MySQL