1.存儲過程描述sql
用於修改主鍵生成表中的遞增值session
2.存儲過程實現ide
SELECT @@global.sql_mode;spa
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); ##當前session變量生效圖片
DELIMITER //generator
-- proc_modify_primary_key_value:存儲過程名稱it
DROP PROCEDURE IF EXISTS `proc_modify_primary_key_value`;io
-- table_name:表名 set_column_name:需求設置的列 set_column_name_value:需求設置的列對應的值 condition_column_name:條件列 condition_column_name_value:條件列值table
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))class
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')