2

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
  • 2
    Look at the information_schema.* tables. I think some combination of it's data will probably work well (columns, table_constraints & triggers perhaps). Commented Apr 25, 2012 at 14:36

1 Answer 1

5

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);
Sign up to request clarification or add additional context in comments.

3 Comments

if you could include that regexp function please
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)
good point! depends on what you want to detect.. you could filter out that as well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.