当前位置:网站首页>记录一次存储过程批量修改表结构
记录一次存储过程批量修改表结构
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 ;
边栏推荐
- C# List 集合对象去重 Linq去重 带时间去重
- MySQL one line to many lines (split according to specific symbols)
- Autojs learning-2048 small game automation
- Week 2022/7/16
- 使用Everything清理垃圾文件
- MySQL中判断和向下取整的使用场景和用法
- 删除文件 unable to find or create trash dirctory
- HighTec 新建 AURIX TC37X demo 工程
- Rk1126 realizes picture in picture function picture in picture for rk 1126
- An easy-to-use network liar reporting system without encrypted version source code
猜你喜欢

Gin框架原理

高仿网易云音乐UI的微信小程序源码

Only when the data analysis report is written in this way can we really understand the data

Tasking 新建 AURIX TC37X demo 工程

Overview of Baidu map technology, and application development of basic API and webapi

Unity UMP打包黑屏問題總結

智能硬件语音控制的时频图分类挑战赛2.0(思路以及结果,目前top5)

Install go:tools failed to install in vscode

‘ionic‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。

Real time Bi (IV) low cost data quasi real time processing idea
随机推荐
Efficient insertion of references in word with thousands of words and many pictures
JS中Class类的静态属性和静态方法
Pytorch image models (Timm) library
Kettle5.4 problem record
物业小区高校水电抄表充值管理系统
CKA 核心知识点概述
word使用技巧
探索:制药厂系统网络时钟同步(NTP时间同步服务器)
Only when the data analysis report is written in this way can we really understand the data
MySQL中判断和向下取整的使用场景和用法
An easy-to-use network liar reporting system without encrypted version source code
对于每一个 Provider 实例都会维护多个连接
[daily question] sword finger offer II 041 Average value of sliding window
OpenLDAP自定义schema
T + 0 to t + 1! The quick redemption amount is reduced to 10000! Another bank adjusted the rules for the application and redemption of cash wealth management products
C list set object de duplication LINQ de duplication with time de duplication
README. MD add directory
Install go:tools failed to install in vscode
masm32写程序
Sphinx遇到的问题