CREATE DEFINER=`root`@`%` PROCEDURE `useCursor`()
BEGIN
DECLARE oneAddr varchar(100) default '';
DECLARE allAddr varchar(100) default '';
DECLARE done INT DEFAULT 0;
DECLARE curl CURSOR FOR select table_name from information_schema.tables where table_schema='test';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN curl;
REPEAT
FETCH curl INTO oneAddr;
IF not done THEN
if (select count(*) from information_schema.columns where table_name = oneAddr and column_name = 'form_key') = 0 THEN
set @sql=concat('alter table ',oneAddr,' add (form_key VARCHAR(120) COMMENT "表单键值")');
PREPARE stmt from @sql;
execute stmt;
END IF;
if (select count(*) from information_schema.columns where table_name = oneAddr and column_name = 'form_table_code') = 0 THEN
set @sqlA=concat('alter table ',oneAddr,' add (form_table_code VARCHAR(120) COMMENT "表单配置表名表code")');
PREPARE stmtA from @sqlA;
execute stmtA;
END IF;
END IF;
UNTIL done END REPEAT;
select allAddr;
CLOSE curl;
END
mysql insert+selecte 主键用uuid()
INSERT INTO xxx(id,name)
SELECT md5(UUID()) id, name from xxx
网友评论