目录
一、MySql函数
1、MySql函数批量创建索引
2、MySql函数批量删除表数据
一、MySql函数
1、MySql函数批量创建索引
创建mysql函数名createIndex
CREATE DEFINER=`root`@`%` PROCEDURE `createIndex`()
BEGIN
DECLARE done int DEFAULT 0;
DECLARE tnm VARCHAR(128);
DECLARE cnt int DEFAULT 0;
DECLARE sql_str VARCHAR(128);
#
DECLARE cur_tbls CURSOR FOR
SELECT
c.table_name
FROM
information_schema.`TABLES` t
INNER JOIN information_schema.`COLUMNS` c ON t.table_name=c.table_name
AND t.table_schema=c.table_schema
AND t.table_schema='表名'
AND c.column_name='表列名'
WHERE
NOT EXISTS (SELECT d.`NAME` FROM information_schema.`INNODB_INDEXES` d WHERE d.`NAME`=concat(t.table_name,'_idx1'));
DECLARE CONTINUE HANDLER FOR NOT found set done=1;
#
open cur_tbls;
#
www:loop
FETCH cur_服务器托管网tbls INTO tnm;
IF done=1 then
leave www;
end IF;
set sql_str='';
set sql_str=CONCAT('ALTER table ',tnm,' ADD INDEX ',tnm,'_idx1(`列1`,`列2`);');
set @sql =sql_str;
PREPARE s1 from @sql;
EXECUTE s1;
DEALLOCATE PREPARE s1;
#
set cnt = cnt +1;
end loop;
#
COMMIT;
select CONCAT('结束',cnt);
CLOSE cur_tbls;
END
2、MySql函数批量删除表数据
创建mysql函数名DeleteData
CREATE DEFINER=`root`@`%` PROCEDURE `DeleteData`()
BEGIN
DECLARE done int DEFAULT 0;
DECLARE tnm VARCHAR(128);
DECLARE cnt int DEFAULT 0;
DECLARE sql_str VARCHAR(2000);
DECLARE file_str VARCHAR(50) DEFAULT '';
#
DECLARE cur_tbls CURSOR FOR
SELECT
c.table_name
FROM
information_schema.`TABLES` t
INNER JOIN information_schema.`COLUMNS` c ON t.table_name=c.table_name
AND t.table_schema=c.table_schema
AND t.table_schema='表名'
AND c.column_name='服务器托管网表列名';
#
DECLARE cur_delete_nms CURSOR FOR
SELECT 'NM1' AS F1 FROM DUAL UNION ALL
SELECT 'NM2' AS F1 FROM DUAL;
DECLARE CONTINUE HANDLER FOR NOT found set done=1;
#
open cur_delete_nms;
#
www:loop
FETCH cur_delete_nms INTO file_str;
IF done = 1 then
leave www;
end IF;
set sql_str='';
set sql_str=CONCAT('DELETE FROM ',tnm,' WHERE 列名= ',file_str,';');
set @sql =sql_str;
PREPARE s1 from @sql;
EXECUTE s1;
DEALLOCATE PREPARE s1;
#
set cnt = cnt +1;
end loop;
CLOSE cur_delete_nms;
#
COMMIT;
select CONCAT('结束',cnt);
END
不断学习才能不断提高!
生如蝼蚁,当立鸿鹄之志,命比纸薄,应有不屈之心。
乾坤未定,你我皆是黑马,若乾坤已定,谁敢说我不能逆转乾坤?
努力吧,机会永远是留给那些有准备的人,否则,机会来了,没有实力,只能眼睁睁地看着机会溜走。
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
服务器托管网 文章目录 什么是动态规划 正文 力扣题 第 N 个泰波那契数 三步问题 使用最小花费爬楼梯 总结 什么是动态规划 线性动态规划:是可以用一个dp表来存储内容,并且找到规律存储,按照规律存储。让第i个位置的值等于题目要求的答案 >dp表:dp…