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处收到语法错误
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处收到语法错误
AFAIK,您只能像在例程(函数、触发器、存储过程)中那样使用 IF。
创建一个存储过程:
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
,所以我为你改变了。