Search code examples
mysqlcopysql-likecreate-tabledatabase-trigger

MySQL - Duplicate a Table WITH Triggers


I am trying to duplicate a table with triggers. I know that I've done this before, I just can't remember how I did it and where I learned how to do it. I've tried CREATE TABLE newname LIKE oldname and CREATE TABLE newname AS oldname, along with CREATE TABLE newname SELECT * FROM oldname. None of those queries seem to be copying triggers. I've followed this, this, and this, and again, no luck. Is there any way that I can copy triggers when duplicating/creating a new table?


Solution

  • The short answer is: you cannot do this with a single sql statement.

    The reason is that triggers are not part of the table, they are an entirely different object that happens to be related to a table.