Page 1 of 1

Mysql Create Table (non-existing)

Posted: Sun Jul 15, 2007 10:44 am
by tecktalkcm0391
I have a page that creates a table in a database. How can I make this code so if the table doesn't exist create it. Do I just do a select table before and if it returns something don't create the table?

Posted: Sun Jul 15, 2007 11:03 am
by Oren
http://dev.mysql.com/doc/refman/5.0/en/ ... table.html:

Code: Select all

CREATE TABLE IF NOT EXISTS tbl_name

Posted: Sun Jul 15, 2007 11:04 am
by volka
Mysql has an extension to the CREATE TABLE syntax
http://dev.mysql.com/doc/refman/5.0/en/create-table.html wrote:CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
but that's mysql specific.

But why not simply trying to create the table. If it already exists you get a specific error signaled.

Posted: Sun Jul 15, 2007 11:36 am
by feyd
PHP - Code :arrow: Databases. :?

Posted: Sun Jul 15, 2007 10:33 pm
by tecktalkcm0391
Thanks. I got it working...
feyd wrote:PHP - Code :arrow: Databases. :?
sorry. i forgot :oops: