Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given already created SQL databases, is there any way to generate the DDL SQL statements to recreate the database?

share|improve this question
Your phpmyadmin tag suggests a MySQL database, but please edit your question to include the database type. – Jan Doggen Mar 7 '13 at 10:14
The answer to this is different for each DBMS. Could you edit your question to clarify which DBMS this is about? – sleske Mar 7 '13 at 11:08
There are lots of GUI tools for different DBs and SQL variants that can do what you want (select tables and export as DDL and data SQL files so everything can be recreated). – Karan Mar 7 '13 at 19:24
up vote 7 down vote accepted

Given that you have tagged phpMyAdmin, just use the export feature for the whole database. You will be given the option to choose a format, and SQL is one of the options.

mysqldump will do the same thing, with many more options.

share|improve this answer

The statement SHOW CREATE table, with table the name of the table you're interested in, will give you the query executed to create the table, on the column Create table, and with SHOW CREATE DATABASE database, you'll have the query to create the database itself.

Combining the two should allow you to get what you want.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .