sqlite中只支持 ALTER TABLE 命令的 RENAME TABLE 和 ADD COLUMN。 其余类型的 ALTER TABLE 操做如 DROP COLUMN,ALTER COLUMN,ADD CONSTRAINT 等等均被忽略。sql
重命名表名:server
alter table tableName rename to newTableNamesqlite
添加列it
alter table tableName add columnName columnTypetable
这两个和sql server基本一致,用起来挺方便,可是后面就有点蓝瘦了ast
删除列select
create table copyTableName (fields)方法
insert into copyTableName (fields) select fields from tableName命名
dorp table tableName数据
alter table copyTableName rename to tableName
首先建立个新表,而后将原表数据转移到新表,固然这时候新表的fields只保留了不删除的字段,而后将原表删除,再将新表的名字改回原来的表名
修改列
实现方法和删除列思路相同,只是fields里面不止要删除原来的列,还要添加新的列名和类型
其余的暂时没有遇到,下面记录一下,中间用到的关于sqlite的一些知识
获取表的建立sql
select sql from sqlite_master where name='tableName' and type='table'
获取表的全部字段
PRAGMA table_info('tableName')
判断表是否存在
select count(*) from sqlite_master where type='table' and name = 'tableName'
嗯,,,中规中矩的一篇记录文