截断 SQLite 表(如果存在)? [英] Truncate a SQLite table if it exists?

查看:23
本文介绍了截断 SQLite 表(如果存在)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要在 SQLite 中截断表,我需要使用以下语法:

To truncate a table in SQLite I need to use this syntax:

DELETE FROM someTable

但是如何仅在表存在时才截断它?

But how do I truncate the table only if it exists?

不幸的是,这会引发错误:

Unfortunately this throws an error:

DELETE FROM someTable IF EXISTS

这也不起作用:

DELETE IF EXISTS FROM someTable

谢谢.

推荐答案

恕我直言,删除表并重新创建它更有效.是的,在这种情况下,您可以使用IF EXISTS".

IMHO, it is more efficient to drop the table and re-create it. And yes, you can use "IF EXISTS" in this case.

这篇关于截断 SQLite 表(如果存在)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆