Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.3k views
in Technique[技术] by (71.8m points)

mariadb - Context of MySQL wildcards

I am trying to get a better understanding of the context in which MySQL interprets wildcards, especially the _ underscore wildcard, which matches exactly one character. For example, it is a common practice to use snake case in naming databases and tables (e.g. my_sample_database and my_table) and in that context MYSQL does not treat the _ underscore character as a wildcard.


We create table named my_table and populate it as follows:

CREATE TABLE my_table
(
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  name CHAR(40) NOT NULL DEFAULT '',
  age INT NOT NULL DEFAULT 0,
  PRIMARY KEY(id)
);

INSERT INTO my_table(name, age) VALUES('William', 25);

We create table named my0table and populate it as follows:

CREATE TABLE my0table
(
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  name CHAR(40) NOT NULL DEFAULT '',
  age INT NOT NULL DEFAULT 0,
  PRIMARY KEY(id)
);

INSERT INTO my0table(name, age) VALUES('Bart', 15);

Sample database has two tables:

mysql> SHOW TABLES;
+------------------------------+
| Tables_in_my_sample_database |
+------------------------------+
| my0table                     |
| my_table                     |
+------------------------------+
2 rows in set (0.00 sec)

We execute the select statement and the DB gives unambiguous results:

mysql> SELECT * FROM my_table;
+----+---------+-----+
| id | name    | age |
+----+---------+-----+
|  1 | William |  25 |
+----+---------+-----+
1 row in set (0.01 sec)

mysql> SELECT * FROM my0table;
+----+------+-----+
| id | name | age |
+----+------+-----+
|  1 | Bart |  15 |
+----+------+-----+
1 row in set (0.00 sec)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...