SQLite数据库有效执行的最佳SQL是什么:
If Database Table Exists then
- create table
- insert row
- insert row (i.e. for startup data)
end
Run Code Online (Sandbox Code Playgroud)
Yaq*_*mad 24
要检查您的表是否存在,您可以使用:
SELECT * FROM sqlite_master WHERE name ='myTable' and type='table';
Run Code Online (Sandbox Code Playgroud)
您可以让Sqlite自己为您检查一下:
CREATE TABLE IF NOT EXISTS <table_name> ...;
Run Code Online (Sandbox Code Playgroud)
按照文档链接:https : //sqlite.org/lang_createtable.html
小智 5
使用此代码
SELECT name FROM sqlite_master WHERE type='table' AND name='yourTableName';
Run Code Online (Sandbox Code Playgroud)
如果返回的数组计数等于 1,则表示表存在,否则不存在。