开发者

mysql create table like to query?

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 man开发者_Python百科agement consoles Send To editor feature?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜