SQLite - 如果不存在则创建表 [英] SQLite - create table if not exists
问题描述
SQLite 中的 create table 语句意味着返回什么?
What is the create table statement in SQLite meant to return?
我观察到 create table if not exist
当表确实存在时返回 0
和 1
.返回值是否是表是否存在的可靠指示?如果表已经存在,我希望该语句返回 0
,如果不存在,则返回 1
,类似于 insert
语句.
I have observed create table if not exists
returning both a 0
and 1
when the table does in fact exist. Is the return value a reliable indication of whether the table does exist or not? I would expect the statement to return a 0
if the table already exists and a 1
when it does not, similar to an insert
statement.
推荐答案
Changes
返回受影响的行数.该值对于 CREATE TABLE
语句没有意义.
Changes
returns the number of affected rows.
This values is meaningless for CREATE TABLE
statements.
没有简单的方法可以确定 CREATE TABLE IF NOT EXISTS
语句是否进行了创建.您应该事先检查 PRAGMA table_info.
There is no easy way to determine whether the CREATE TABLE IF NOT EXISTS
statement did the creation or not.
You should check beforehand with PRAGMA table_info.
这篇关于SQLite - 如果不存在则创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!