In my php script I want to check if a structure of database table has changed. The DESCRIBE TABLE wont provide enough informations, because it ignores the foreign keys. The SHOW CREATE TABLE is too much, because auto incremental value also appears here.
1 Answer
The SHOW CREATE TABLE is too much, because auto incremental value also appears here.
Just filter out the auto incremental value with a regexp.
preg_replace('/ AUTO_INCREMENT=[0-9]+ /', ' ', $sql);
3 Comments
John Smith
if you could include that regexp function please
ypercubeᵀᴹ
Nice. (minor drawback is that it will show false negative if an index or a foreign key has been dropped and recreated with different name)
Karoly Horvath
good point! depends on what you want to detect.. you could filter out that as well
information_schema.*tables. I think some combination of it's data will probably work well (columns, table_constraints & triggers perhaps).