1.存储过程描述
用于修改主键生成表中的递增值
2.存储过程实现
SELECT @@global.sql_mode;
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); ##当前session变量生效
DELIMITER //
-- proc_modify_primary_key_value:存储过程名称
DROP PROCEDURE IF EXISTS `proc_modify_primary_key_value`;
-- table_name:表名 set_column_name:需求设置的列 set_column_name_value:需求设置的列对应的值 condition_column_name:条件列 condition_column_name_value:条件列值
CREATE PROCEDURE `proc_modify_primary_key_value` (IN table_name VARCHAR(20),IN set_column_name VARCHAR(30),IN set_column_name_value VARCHAR(30),IN condition_column_name VARCHAR(30),IN condition_column_name_value VARCHAR(30))
COMMENT '用于修改主键生成表中的递增值'
BEGIN
set @sql_update = CONCAT("UPDATE ",table_name," SET ",set_column_name," = ",set_column_name_value," WHERE ",condition_column_name," = ",condition_column_name_value);
PREPARE sql_update from @sql_update;
EXECUTE sql_update;
DEALLOCATE PREPARE sql_update;
END;
//
DELIMITER ;
3.调用存储过程
SELECT @@global.sql_mode;
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); ##当前session变量生效
CALL proc_modify_primary_key_value('primary_key_generator_table','value','1','name','PK_CUSTOMER_ID')