有没有办法测试SQLite数据库中是否存在表?现在,我正在try catch块中创建表,如果抛出异常,我知道该表已经创建。当然必须有一个更好的方法,对吗?
答案 0 :(得分:7)
要检测特定表是否存在,请使用:
SELECT name
FROM sqlite_master
WHERE type = 'table'
AND name LIKE '%your_table_name%'
答案 1 :(得分:4)
有一个名为sqlite_master
的表,其中包含数据库架构。您可以运行如下查询:
select count(*) from sqlite_master where name='users';
如果查询返回1,则表'users'存在。您还可以使用if not exists
SQL构造:
create table if not exists users (name, pwd);