1297
MariaDBerrorstored-procedureshigh confidence
Stored procedure already exists
Production Risk
Low — DDL fails; existing routine is unchanged.
What this means
CREATE PROCEDURE or CREATE FUNCTION failed because a routine with that name already exists in the database.
Why it happens
- 1Running a migration script twice
- 2Not using DROP IF EXISTS before CREATE
How to reproduce
trigger — this will error
trigger — this will error
CREATE PROCEDURE my_proc() BEGIN SELECT 1; END; -- run twice
expected output
ERROR 1297 (42000): PROCEDURE my_proc already exists
Fix 1
Drop before creating
Drop before creating
DROP PROCEDURE IF EXISTS my_proc; CREATE PROCEDURE my_proc() BEGIN SELECT 1; END;
Why this works
Ensures a clean create without error.
Fix 2
Use CREATE OR REPLACE (MySQL 8.0+)
Use CREATE OR REPLACE (MySQL 8.0+)
CREATE OR REPLACE PROCEDURE my_proc() BEGIN SELECT 1; END;
Why this works
Atomically replaces an existing routine.
What not to do
✕
Version notes
Sources
Official documentation ↗
MySQL 8.0 — 1297 ER_SP_ALREADY_EXISTS
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev