mysql 中可以更改的存储过程替代方案 [英] stored procedure alternative in mysql which can be altered

查看:93
本文介绍了mysql 中可以更改的存储过程替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1.) mysql 中存储过程的替代方案,可以更改而不是删除并重新创建

1.) alternative for stored procedure in mysql which can be altered rather than drop and create again

2.) 维护数据库版本的简单方法我目前正在手动创建 log.sql 文件,例如示例 log.sql 文件

2.) easy ways to maintain database version i am currently creating log.sql files manually such as example log.sql file

ALTER TABLE `ship` 
CHANGE COLUMN `is_deleted` `is_deleted` INT(11) NULL DEFAULT 0 ;
DROP procedure IF EXISTS `get_ship`;
DELIMITER ;;
CREATE PROCEDURE `get_ship`(

)
BEGIN
 do something;    
end if;
END ;;
DELIMITER ;

有没有更好更简单的方法来创建这样的sql日志文件,我已经尝试过MYSQL工作台

Is there an better and easy way to create such sql log files, I have already tried MYSQL workbench

推荐答案

当您使用以下任一方式重新定义表结构时

When you are redefining a table structure with any of the following

  1. 删除列,
  2. 更改列,
  3. 修改列,
  4. 添加列,
  5. 重命名表

并且您的存储过程依赖于同一个表及其预定义的列,那么您别无选择,只能重新定义部分存储过程.

and your stored procedure has dependency on the same table and its pre-defined columns, then you don't have a choice but redefine part of your stored procedure.

而这只能通过删除并重新创建程序来实现.

And this can only be achieved by dropping and re-creating the procedure again.

根据 ALTER PROCEDURE 上的文档语法,在MySQL中,

As per documentation on ALTER PROCEDURE Syntax, in MySQL,

但是,您不能使用此语句更改存储过程的参数或主体;要进行此类更改,您必须删除并使用 DROP PROCEDURE 和 CREATE PROCEDURE 重新创建过程.

add column 可能不需要重新构建您的存储过程,除非新列也参与了该过程的算法.

add column may not require re-building your stored procedure unless the new column too participates in the procedure's algorithm.

这篇关于mysql 中可以更改的存储过程替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆