6

Can we get a 'create table' command from description (describe )? I have a table whose description I can get from "DESC TableName". I wish to know if I can get how that table was created (so that I can use the same command for something else)?. I can get sql-dump but I want to know if there is another way. Thanks in advance !

2
  • 'how the table was created'--will you explain a bit Commented Nov 19, 2013 at 9:49
  • I meant the actual command which created that table. Thanks to @Sashi, I got it now. It's 'Show create table tableName'. Commented Nov 19, 2013 at 10:12

3 Answers 3

13

Try this :::

Show create table tableName
Sign up to request clarification or add additional context in comments.

Comments

5

If you are looking to make a new empty table with the same structure and attributes, you can use:

CREATE TABLE newTable LIKE tableName

create table reference

3 Comments

Thanks a lot Tom. Actually, I wanted to know if I can get that SQL command which created that particular table.
No problem, I've added an explanation of what my answer does instead.
It certainly is helpful. I was not aware of this command too. Thanks for letting me know about it.
2

Also :

SHOW CREATE TABLE tbl_name

Shows the CREATE TABLE statement that creates the named table. To use this statement, you must have some privilege for the table. This statement also works with views.

Refer: http://dev.mysql.com/doc/refman/5.6/en/show-create-table.html

1 Comment

Sure Sathish. I got it now. Thanks a lot..! :)

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.