2

Is it possible to use the create table query (create table t2 like t1) to get the query instead the actual table? Kind of like duplicating some management consoles Send To editor feature?

2
  • Are you looking for SHOW CREATE TABLE tablename;? Commented Jul 9, 2011 at 20:27
  • 2
    yes, make it an answer so I can give you credit :) Commented Jul 9, 2011 at 20:40

1 Answer 1

3

I think you're looking for SHOW CREATE TABLE tablename;

'tablename' can be the table within the current database, if you've selected one, or you can qualify it as in 'dbname.tablename'. The output can be used to create the table again. In fact, I sometimes use it in scripts that need to either use an existing table or create it if it doesn't exist. First I'll get the table creation info as shown above, and then I'll use something like"

CREATE TABLE IF NOT EXISTS tablename .........

Where '..........' is all the goodies that SHOW CREATE TABLE tablename gives me.

If you're interested in a good tutorial on MySQL (the database), as well as SQL (the language), you might have a look at the O'Reilly book, Learning MySQL. It's pretty good.

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

Comments

Your Answer

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