U moet Dynamische SQL hier, als Default
clausule in de Alter Table
zal de variabele waarde niet kunnen oplossen:
DELIMITER $$
CREATE PROCEDURE updateDefaultUserRole(
IN rid_in INT
) BEGIN
-- generate the query string for Alter Table
SET @alter_query_str = CONCAT('ALTER TABLE _users
MODIFY rid INT(255) NOT NULL
DEFAULT ',
rid_in); -- Modify the columns default value
-- prepare the query
PREPARE stmt FROM @alter_query_str;
-- execute the query
EXECUTE stmt;
-- deallocate the query
DEALLOCATE PREPARE stmt;
UPDATE _users SET rid = rid_in
WHERE rid < rid_in; -- Update all entries lower than the role ID.
END $$
DELIMITER ;