当前位置:网站首页>If [not] exists in MySQL
If [not] exists in MySQL
2022-06-29 10:26:00 【A ray of sunshine a】
Recently MySQL Developing distributed database based on database , Need to support a if [not] exists grammar . To study the SQL Grammar analysis part , Sum up :
1、 stay MySQL in , Support when creating tables create table if not exists db.table_name ....
create table if not exists test1
(
c1 int primary key,
c2 varchar(50)
)engine = innodb;If the table to be created exists , Then return directly , You are not recreating the table .
If the watch doesn't exist , Then create the table .
2、drop One table , Need to support if exists grammar :
drop table if exists test1;If you want to drop The specified table does not exist , directly drop fall
If you want to drop The table of does not exist , Will display a warnings, as follows :
+-------+------+-----------------------------+
| Level | Code | Message |
+-------+------+-----------------------------+
| Note | 1051 | Unknown table 'mysql.test1' |
+-------+------+-----------------------------+
1 row in set (0.00 sec)
Come to a general process , Include create/drop if [not] exists Prompt for statement :
Cluster[mysql]> create table test1
-> (
-> c1 int primary key,
-> c2 varchar(50)
-> )engine = innodb;
Query OK, 0 rows affected (0.06 sec)
Cluster[mysql]> create table test1
-> (
-> c1 int primary key,
-> c2 varchar(50)
-> )engine = innodb;
ERROR 1050 (42S01): Table 'test1' already exists
Cluster[mysql]>
Cluster[mysql]>
Cluster[mysql]>
Cluster[mysql]>
Cluster[mysql]> create table if not exists test1
-> (
-> c1 int primary key,
-> c2 varchar(50)
-> )engine = innodb;
Query OK, 0 rows affected, 1 warning (0.02 sec)
Cluster[mysql]> show warnings;
+-------+------+------------------------------+
| Level | Code | Message |
+-------+------+------------------------------+
| Note | 1050 | Table 'test1' already exists |
+-------+------+------------------------------+
1 row in set (0.00 sec)
Cluster[mysql]> drop table test1;
Query OK, 0 rows affected (0.05 sec)
Cluster[mysql]> drop table test1;
ERROR 1051 (42S02): Unknown table 'mysql.test1'
GreatDB Cluster[mysql]>
GreatDB Cluster[mysql]>
GreatDB Cluster[mysql]> drop table if exists test1;
Query OK, 0 rows affected, 1 warning (0.02 sec)
Cluster[mysql]> show warnings;
+-------+------+-----------------------------+
| Level | Code | Message |
+-------+------+-----------------------------+
| Note | 1051 | Unknown table 'mysql.test1' |
+-------+------+-----------------------------+
1 row in set (0.00 sec)边栏推荐
- 2019-11-10 training summary
- C#窗体向另一个窗体实时传值
- Picture verification code control
- 《CLR via C#》读书笔记-加载与AppDomain
- std::unique_ptr<T>与boost::scoped_ptr<T>的特殊性
- Text of the basic component of the shutter
- QGIS mapping
- The Stones Game【取石子博弈 & 思维】
- Codeforces Round #659 (Div. 2)
- L2-3 is this a binary search tree- The explanation is wonderful
猜你喜欢
随机推荐
manacher
逆向思维-小故事
Acwing271 [teacher Yang's photographic arrangement] [linear DP]
在VMware workstation中安装WMware ESXi 6.5.0并进行配置
1099 build a binary search tree (30 points)
查看CSDN的博客排名
在实践中学习Spark计算框架(01)
Codeforces - 1151b thinking
Web vulnerability manual detection and analysis
Codeforces Round #645 (Div. 2)
《CLR via C#》读书笔记-CLR寄宿与AppDomain
Beautiful ruins around Kiev -- a safe guide to Chernobyl!
Download control 1 of custom control (downloadview1)
2019.10.27 training summary
To 3 --- 最后的编程挑战
winform使用zxing生成二维码
SeaweedFS安全配置(Security Configuration)
September 25, 2020 noncopyable of boost library for singleton mode
这个开源项目超哇塞,手写照片在线生成
[51nod 1215] array width









