需求說明:
在創建表的時候,如果指定if not exists語句,有什么作用,在此做個實驗,並且官方手冊,
理解下這個參數的作用.
操作過程:
1.創建測試表test01
mysql> create table test01 (id int);
Query OK, 0 rows affected (0.08 sec)
2.不指定if not exists語句,創建test01表
mysql> create table test01 (id int); ERROR 1050 (42S01): Table 'test01' already exists
備注:如果不指定if not exists語句,創建同名表的時候就會報錯.
3.指定if not exists語句創建表
mysql> create table if not exists test01 (id01 int); #雖然字段不同,但是仍然不能創建. Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> show warnings; +-------+------+-------------------------------+ | Level | Code | Message | +-------+------+-------------------------------+ | Note | 1050 | Table 'test01' already exists | +-------+------+-------------------------------+ 1 row in set (0.00 sec)
備注:指定了if not exists語句來創建表,雖然表名是存在的,但是創建沒有報錯,但是存在警告信息,警告中信息是表已經存在了.
另:兩次創建的表,雖然字段不同不同,表名相同,還是不允許創建.
小結:
1.如果指定了if not exists語句來創建表,如果表存在,也不會報錯
2.創建表的語句不會驗證要創建的表與已經存在的表的結構是否一致,只要名字相同就不允許創建.
文檔創建時間:2018年6月11日21:26:54