当前位置:网站首页>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)边栏推荐
猜你喜欢
随机推荐
Web vulnerability manual detection and analysis
September 25, 2020 noncopyable of boost library for singleton mode
I would like to know how to open an account for free online stock registration? In addition, is it safe to open a mobile account?
2019.10.30 learning summary
Codeforces Round #641 Div2
2019.10.23 training summary
子串分值-超详细版——最后的编程挑战
Win32Exception (0x80004005): 组策略阻止了这个程序。要获取详细信息,请与系统管理员联系。
MySQL中innodb_page_cleaners详解
Use of Azkaban in task scheduler
信号作品:时变和时不变
HDU 6778 car (group enumeration -- > shape pressure DP)
To 3 -- the last programming challenge
同花顺炒股软件可靠吗,安全吗?
2019.10.6 training summary
Is it safe to open a stock account with the QR code given by the manager of a securities firm? I want to open an account
解决zxing的QR码包含中文时乱码的问题
1147 Heaps (30 分)
Voir le classement des blogs pour csdn
2020-09-18 referer authentication URL escape









