gpt4 book ai didi

MySQL:如果存在...截断

转载 作者:行者123 更新时间:2023-11-29 01:09:48 27 4
gpt4 key购买 nike

想要截断一个存在的表:

IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'mytable') TRUNCATE mytable

错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'mytable') ' at line 1

我也尝试在 ) 之后添加 THEN,但问题似乎出在 IF 处。

最佳答案

您需要以下两个语句来执行此操作:

create table if not exists <mytable>;

truncate table <mytable>;

关于MySQL:如果存在...截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34063042/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com