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
答案 0 :(得分:3)
AFAIK,你只能在例程(函数,触发器,存储过程)中使用IF。
答案 1 :(得分: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
,所以我为你改变了。