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:
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
also probably a good idea.
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.
相关文章推荐
- [转帖]HOWTO rename column name in Sqlite3 database
- csharp: DataTable Rename ColumnName and remove Column
- sqlite: ambiguous column name解决方法
- 解决 android 下sqlite3_column_table_name 编译不过的问题
- csharp: DataTable Rename ColumnName and remove Column
- ASP.Net MVC – What are the uses of Display, DisplayName, DisplayFormat and ScaffoldColumn attributes
- SQLServer 替换 null 值 函数 isnull(columnname,char)
- ERROR 1366 (HY000): Incorrect string value: '\xE4\xB8\xAD\xE5\x9B\xBD' for column 'tname' at row 1
- MySQL数据库-错误1166 Incorrect column name
- Linux Change or Rename User Name and UID
- ResultSetMetaData类的getColumnName和getColumnLabel的不同
- mysql 数据库 错误 Data truncation: Data too long for column 'name' at row 1
- java-mysql异常<Data truncation: Data too long for column 'name ' at row 1>讨论
- 日常坑-page1.jsp (line: 1, column: 96) The JSP specification requires that an attribute name is precede
- ASP.Net MVC – What are the uses of Display, DisplayName, DisplayFormat and ScaffoldColumn attributes
- jdbc-mysql基础 ResultSetMetaData getColumnName getColumnLabel 得到列的名字和别名
- Python解析json之ValueError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
- SQL Error: 957, SQLState: 42000 & ORA-00957: duplicate column name
- select count(column_name) form table_name or select count(*) from table_Name
- 当获取相似数据时,使用不同方法调用不同sp,但是使用同一个方法去用IIDataReader或者SqlDataReader读取数据时需要判断column name是否存在。