0

I am creating table in MySql by using the coomand, create table person ( id int, name int). Actually, I want to create table person if there exists no person table in database. Can anybody help me, how to acive this ?

alessandro
  • 1,681
  • 10
  • 33
  • 54
  • This might help: http://stackoverflow.com/questions/84330/mysql-create-table-if-not-exists-else-truncate – Dan Feb 02 '12 at 22:23
  • Or this: http://stackoverflow.com/questions/9069179/if-table-does-not-exist-execute-a-long-query/9069391#9069391 – thursdaysgeek Feb 02 '12 at 22:40

4 Answers4

4

How about CREATE TABLE IF NOT EXISTS person (id INT, name INT)?

Managu
  • 8,849
  • 2
  • 30
  • 36
2

The manual page says that you should use

CREATE TABLE IF NOT EXISTS person (id int, name int);
Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
2
CREATE TABLE IF NOT EXISTS person (id int, ...);

See manual.

jcmeloni
  • 1,259
  • 1
  • 15
  • 21
1

Use IF NOT EXISTS:

create table if not exists person ( id int, name int).

See MySQL documentation

peterept
  • 4,407
  • 23
  • 32