要檢查表是否存在,請使用以下語法 ?
CREATE TABLE IF NOT EXISTS yourTableName ( yourColumnName1 dataType, . . . . N );
登錄后復(fù)制
在這里,我們將嘗試創(chuàng)建一個已經(jīng)存在的表,然后它將產(chǎn)生一個警告信息“表已經(jīng)存在”。讓我們首先創(chuàng)建一個表。這個表已經(jīng)存在−
mysql> CREATE TABLE IF NOT EXISTS DemoTable ( Id int ); Query OK, 0 rows affected, 1 warning (0.06 sec)
登錄后復(fù)制
The warning message is as follows −
mysql> show warnings;
登錄后復(fù)制
Output
+-------+------+-------------------------------------+ | Level | Code | Message | +-------+------+-------------------------------------+ | Note | 1050 | Table 'DemoTable' already exists | +-------+------+-------------------------------------+ 1 row in set (0.00 sec)
登錄后復(fù)制
如果表還不存在,則會被創(chuàng)建 −
mysql> CREATE TABLE IF NOT EXISTS DemoTable2 ( Id int ); Query OK, 0 rows affected (0.71 sec)
登錄后復(fù)制
以上就是檢查MySQL中的表是否存在,如果存在則顯示警告?的詳細內(nèi)容,更多請關(guān)注www.92cms.cn其它相關(guān)文章!