I have a par开发者_如何学编程ser that parses XML file into SQLite database, and the current implementation generates the 'create table xyz ...' even the table is already existed.
- Is this OK? I mean, is this OK to run 'create table' even when the table exists in db?
- If not, is there easy way to check the names of tables (and its contents) that SQLite db has?
What you are searching for is CREATE TABLE IF NOT EXISTS and the FAQ entry How do I list all tables/indices contained in an SQLite database.
Creating a table without the "IF NOT EXISTS" option will lead to an error.
You can DROP TABLE
before CREATE TABLE
, you can safety DROP TABLE
who don't exists then you don't must checking for TABLE
existence before DROP
.
SQLite has a "IF NOT EXISTS" clause so that you can throw a "CREATE TABLE" at the database and it will ignore it if it already exists. For example:
CREATE TABLE IF NOT EXISTS mytable ( id INTEGER );
The URL to the documentation about this is at: http://www.sqlite.org/lang_createtable.html
精彩评论