当前位置:网站首页>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)边栏推荐
- 函数指针、函数指针数组、计算器+转移表等归纳总结
- winform使用zxing生成二维码
- Codeforces Round #645 (Div. 2)
- 2019.11.20 training summary
- Ural1517 freedom of choice [suffix array: longest common continuous substring]
- September 25, 2020 noncopyable of boost library for singleton mode
- 這個開源項目超哇塞,手寫照片在線生成
- Time varying and non time varying
- Use of Azkaban in task scheduler
- std::unique_ptr<T>与boost::scoped_ptr<T>的特殊性
猜你喜欢

时变和非时变

Download control 1 of custom control (downloadview1)

Arc view and arc viewpager

nacos注册中心集群

指针数组、数组指针和传参的相关问题

Beautiful ruins around Kiev -- a safe guide to Chernobyl!

Application of Pgp in encryption technology

The Stones Game【取石子博弈 & 思维】

Slide the custom control to close the activity control

Voir le classement des blogs pour csdn
随机推荐
Judgment of points inside and outside polygon
Recyclerview universal adapter package
std::unique_ptr<T>与boost::scoped_ptr<T>的特殊性
EDA与VHDL题库
1098 insertion or heap sort (25 points)
完全二叉树的权值 递归做法 ——最后的编程挑战
2019.10.30 learning summary
Use of Azkaban in task scheduler
MySQL中update一条record的过程
2021年团体程序设计天梯赛-模拟赛
Summary after the 2009 ICPC Shanghai regional competition
这个开源项目超哇塞,手写照片在线生成
信号作品:时变和时不变
L2-3 这是二叉搜索树吗?-题解超精彩哦
The stones game
通过Win32API调用另一界面的按钮
Picture verification code control
C#中Attribute(特性)
mysql 8.0 一条insert语句的具体执行流程分析(二)
If I were in Beijing, where would it be better to open an account? In addition, is it safe to open an account online now?