我可以测试 SQLite 数据库中表的存在吗? [英] Can I test for the existence of a table in a SQLite database?

查看:24
本文介绍了我可以测试 SQLite 数据库中表的存在吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法测试 SQLite 数据库中表的存在?现在,我正在 try catch 块中创建表,如果抛出异常,我知道该表已创建.肯定有更好的方法,对吧?

Is there a way to test for the existence of a table in a SQLite database? Right now, I'm creating the table inside a try catch block, and if that throws an exception I know the table has been created. Surely there has to be a better way, right?

推荐答案

要检测特定表是否存在,请使用:

To detect if a particular table exists, use:

SELECT name 
  FROM sqlite_master
 WHERE type = 'table'
   AND name LIKE '%your_table_name%'

这篇关于我可以测试 SQLite 数据库中表的存在吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆