当前位置:网站首页>记录一次存储过程批量修改表结构
记录一次存储过程批量修改表结构
2022-07-17 04:48:00 【夜夜夜空】
//DELIMITER先将分割符设置成$,因为语句中有许多;,避免中断,修改分隔符
DELIMITER $
CREATE PROCEDURE alter_table_enegine()
BEGIN
DECLARE count int DEFAULT 0 ;
DECLARE var_name VARCHAR(300);
DECLARE `@sqlstr` VARCHAR(2560);
DECLARE tableNames CURSOR FOR SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME LIKE 'terminal%';
SELECT count(*) into count FROM (SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME LIKE 'terminal%') t1;
OPEN tableNames;
WHILE count > 0 DO
FETCH tableNames INTO var_name;
SELECT count(*) INTO @colName FROM information_schema.columns WHERE table_name = var_name AND column_name = 'url';
IF @colName = 0 THEN
SET @sqlstr = CONCAT(
"alter table ",
var_name,
" add url varchar(255) DEFAULT NULL"
);
PREPARE stmt FROM @sqlstr;
EXECUTE stmt;
END IF;
SET count = count - 1;
END WHILE;
END;
-- 执行存储过程
CALL alter_table_enegine();
-- 执行完,删掉临时用的存储过程
DROP PROCEDURE alter_table_enegine;
$
DELIMITER ;
边栏推荐
- 使用__slots__和__dict__来节省空间(简直就是质的飞越,LeetCode亲测有效)
- EasyExcel简单使用
- HCR Huichen is walking on the north slope, a giant beast swimming into digital marketing services
- Android kotlin custom LinearLayout
- C language dynamic memory development and flexible array
- 对称加密与非对称加密
- LeetCode-移除元素
- 删除文件 unable to find or create trash dirctory
- 一款好用的网络骗子举报系统无加密版本源码
- 服务端接口测试-接口测试的测试点【杭州多测师】【杭州多测师_王sir】
猜你喜欢

Install go:tools failed to install in vscode

Mature threads should know how to refuse

C language dynamic memory development and flexible array

VirtualLab基础实验教程-7.偏振(3)

Minio installation, deployment and use

实时BI(四)低成本的数据准实时处理思路

mysql中的视图、触发器和存储过程

EasyExcel简单使用

Rk1126 realizes picture in picture function picture in picture for rk 1126
![[unity] interactive double click](/img/28/8c9c3dd9de413ff8e6373ea111b04f.png)
[unity] interactive double click
随机推荐
[unity] interactive double click
C语言动态内存开辟和柔性数组
Policy mode replaces if else
Wildfly: how to call EJBs from EJBs located in another application
【每日一题】剑指 Offer II 041. 滑动窗口的平均值
C list set object de duplication LINQ de duplication with time de duplication
Gin框架原理
AutoJs学习-2048小游戏自动化
MySQL表的查询进阶
Real time Bi (IV) low cost data quasi real time processing idea
【TA-霜狼_may-《百人计划》】基础渲染光照介绍(一)
Common errors in golang compilation
surging作者出具压测结果
Autojs learning-2048 small game automation
Delete the file unable to find or create trash directory
The n-beats model was released in 2020 and is 3% better than the winner of the M4 competition!
Distributed notes (02) - redis of distributed cache (brief description of uses, features, high availability solutions redis cluster, tweetproxy, CODIS)
Reproduction of XOR and encryption decryption
Oracle操作openldap的权限问题
Eureka, take advantage of the tens of millions of daily visits!