淘先锋技术网

首页 1 2 3 4 5 6 7

ALTER:
alter table tableName add column columnType;
给表添加一列,用于新增属性。
alter table tableName rename to newTableName;
修改表名,用于创建临时表,用于删除列、修改表名、修改列。
DROP:
drop table tableName;
删除表,用于删除临时表。
由于sqlite不支持修改列的类型,所以要修改列的类型需要使用临时表存储当前数据,然后新建一个空的表,通过导数据的方式,来间接实现修改列的类型等。

具体实现:
1. alter table tableName rename to newTableName; 创建临时表。
2. create table if not exists tableName(‘id’ int primary key autoincrement not null unique, …… ); 创建空表。
3. insert into tableName select * from newTableName; 将临时表中的数据导入到空表中。
4. drop table newTableName; 删除临时表。