2009-09-19 40 views

回答

7

要检测一个特定的表存在,使用方法:

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

更好的答案,因为它会检查类型。 – SecretDeveloper 2009-09-19 21:09:09

+0

我认为检查类型没有任何优势。如果现有的索引或触发器具有相同的名称,则仍然无法创建表。 – finnw 2009-09-21 09:56:10

4

有一张名为sqlite_master的表包含数据库模式。您可以运行类似的查询:如果查询返回1

select count(*) from sqlite_master where name='users';

,表“用户的存在。您也可以使用SQL if not exists建设:

create table if not exists users (name, pwd);
相关问题