加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

sqlite判断表或者字段是否存在

发布时间:2020-12-12 23:41:15 所属栏目:百科 来源:网络整理
导读:如何判断sqlite中的数据库表或者字段是否存在,方法是通过sqlite_master表。 sqlite_master表结构如下: [sql] view plain copy CREATE TABLE sqlite_master( typeTEXT, name TEXT, tbl_nameTEXT,108); list-style-type:decimal-leading-zero; color:inherit

如何判断sqlite中的数据库表或者字段是否存在,方法是通过sqlite_master表。

sqlite_master表结构如下:

[sql] view plain copy
  1. CREATETABLEsqlite_master(
  2. typeTEXT,
  3. nameTEXT,
  4. tbl_nameTEXT,108); list-style-type:decimal-leading-zero; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important; list-style-position:outside!important"> rootpageINTEGER,248); line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important; list-style-position:outside!important"> sqlTEXT
  5. );

type --类型,如:table

name--表名

sql --创建表的sql语句。

如何要判断表是否存在,只需要执行查询

copy selectnamefromsqlite_masterwherename='tablename';
如果要判断表中的字段是否存在,只需要执行查询

copy select*name='tablename'andsqllike'%fieldname%';

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读