I have this stored procedure, which has been working for a little while
CREATE PROCEDURE `ProjectFromTemplate`(
IN TemplateID INT,
IN NewProjectID INT
)
BEGIN
INSERT INTO Project_Stage
(
ProjectID,
StageID,
StageIndex,
Time
)
(
SELECT
NewProjectID,
StageID,
StageIndex,
Time
FROM Project_Stage
WHERE ProjectID = TemplateID
);
END
But I decided to add another column to the table, but I didn’t update the procedure accordingly. I would like the procedure to be able to handle any new rows that I add. I need something like this pseudo-SQL
CREATE PROCEDURE `ProjectFromTemplate`(
IN TemplateID INT,
IN NewProjectID INT
)
BEGIN
INSERT INTO Project_Stage
(
ProjectID,
*
)
(
SELECT
NewProjectID,
*
FROM Project_Stage
WHERE ProjectID = TemplateID
);
END
Is there a way to express something like ‘all the subsequent rows’ in MySQL?
Leave out the column clause in your
INSERTto minimize the code changes, but you have to spell out the rest of the columns fromProject_Stageunless it doesn’t contain aProjectIDcolumn. If it doesn’t, then your good.Beware: you might still need to recompile after altering the table, though (I’m not sure how MySQL handles schema changes and compiled procs).