sqlite的一些用法

来源:互联网 发布:windows 国产平板 编辑:程序博客网 时间:2024/05/21 14:46
1、获取数据库文件中表相关的信息
从系统表sqlite_master获取
系统表sqlite_master:
type(类型)、name(名称)、tbl_name(表名称)、root_page(引导页面)、sql(创建表的SQL语句)
获取表名称的SQL语句
select tbl_name from sqlite_master where type = 'table'
获取指定表中的字段名称:
无法直接使用SQL语句获取,只能从创建表的SQL语句中进行分析,用来获取字段名称
select sql from sqlite_master where type = 'table' and tbl_name = table_name
注意:分析sql语句,要把双引号、换行符、回车符去掉,字段之间用逗号分隔。
2、添加表字段
alter table table_name add column col_name data_type;
例如:alter table vul_detail add COLUMN vul_id interge;
备注:
不支持删除表字段;
删除表字段:alter table table_name drop column col_name
3、sqlite的系统表
sqlite_master、sqlite_temp_master、sqlite_sequence、sqlite_stat1
当数据库文件的表存在主键时,才会有后面的两个表
原创粉丝点击