0
SELECT @cnt := COUNT(table_name) 
  FROM information_schema.tables 
 WHERE table_schema = 'TAA' 
   and table_name = 'Clients';

IF (@cnt > 0) THEN
  INSERT INTO `ClientsBAK` SELECT * FROM `Clients`;
END IF;

IF(@cnt > 1) THEN我在错误 1064处收到语法错误

4

2 回答 2

3

AFAIK,您只能像在例程(函数、触发器、存储过程)中那样使用 IF。

于 2010-06-04T22:14:20.380 回答
1

创建一个存储过程:

DELIMITER //
CREATE PROCEDURE BackupClients()
BEGIN

    SELECT @cnt := COUNT(table_name)
    FROM information_schema.tables
    WHERE table_schema = 'TAA'
    AND table_name = 'Clients';

    IF @cnt > 0 THEN
        INSERT INTO `ClientsBAK` SELECT * FROM `Clients`;
    END IF;

END //
DELIMITER ;

CALL BackupClients();

我想你也想要IF @cnt > 0代替IF @cnt > 1,所以我为你改变了。

于 2010-06-04T22:16:16.867 回答