Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

up vote 6 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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.