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'
嗯,,,中規中矩的一篇記錄文