gpt4 book ai didi

c# - 检查mysql表是否存在多个

转载 作者:行者123 更新时间:2023-11-29 07:50:09 25 4
gpt4 key购买 nike

我想检查 Mysql,是否存在 3 个表,但不知何故这不适用于 1 个以上的表?如何检查是否存在 3 个表?

Select count(*) From information_schema.tables
where table_schema = 'userbook' and table_name = 'entry'
and table_name = 'stats' and table_name = 'user';

我正在使用 MySQL-Connector 和 Microsoft Visual Studio 2012。

最佳答案

现在,您正在寻找一个名为 entrystats 和名称 user 的表 - 全部相同时间。您的 COUNT 永远是 0!

您需要使用OR运算符,如下所示:

SELECT COUNT(*)
FROM information_schema.tables
WHERE
table_schema = 'userbook' AND
(table_name = 'entry' OR
table_name = 'stats' OR
table_name = 'user')

您还可以使用IN,这更容易维护:

SELECT COUNT(*)
FROM information_schema.tables
WHERE
table_schema = 'userbook' AND
table_name IN ('entry','stats','user')

在这两种情况下:如果计数为 3,则所有三个表都存在。

关于c# - 检查mysql表是否存在多个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26704908/

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