sqlite中只支持 ALTER TABLE 命令的 RENAME TABLE 和 ADD COLUMN, 其他型別的 ALTER TABLE 操作如 DROP COLUMN,ALTER COLUMN,ADD CONSTRAINT 等等均被忽略,
重命名表名:
alter table tableName rename to newTableName
添加列
alter table tableName add columnName columnType
這兩個和sql server基本一致,用起來挺方便,但是后面就有點藍瘦了
洗掉列
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'
嗯,,,中規中矩的一篇記錄文
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/2508.html
標籤:其它
