Mega Code Archive

 
Categories / MySQL Tutorial / Table
 

IF NOT EXISTS parameter can be used to check if a table exists before you actually create it

CREATE TABLE IF NOT EXISTS tablename (columnname data type); mysql> mysql> CREATE TABLE IF NOT EXISTS employee (id int); Query OK, 0 rows affected (0.03 sec) mysql> mysql> desc employee; +-------+---------+------+-----+---------+-------+ | Field | Type    | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | id    | int(11) | YES  |     | NULL    |       | +-------+---------+------+-----+---------+-------+ 1 row in set (0.01 sec) mysql> mysql> drop table employee; Query OK, 0 rows affected (0.02 sec) mysql>