0

I'm looking to pull a table's create syntax via mysql and php. Is it possible?

I need it for a file that creates table_x automatically every 10 days. Since I update the site constantly and create new fields I'd like the file to be dynamic and use the previous table (instead of me updating it manually each time).

2
  • What happens if you need to recreate your database from scratch? Commented Nov 24, 2011 at 1:29
  • I understand your point, but I don't see why I would need to do that. I'd be able to copy the syntax from a backup. Commented Nov 24, 2011 at 1:38

2 Answers 2

2

Yes you can - use

SHOW CREATE TABLE tablename;

Actually if you want to 'reset' your database I would use TRUNCATE instead

TRUNCATE TABLE tablename
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, had no idea it was that simple.
:-) cool when it does what you want - also checkout TRUNCATE TABLE (added to my answer) it may be more of what you want
0
SHOW CREATE TABLE table_x;

...will output one record with the CREATE syntax. Is that what you're looking for?

Comments

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.