MySQL 的引號型別有哪些?


在 MySQL 中,可以使用反引號和單引號。反引號可用於列名和表名周圍,而單引號可用於列名值。

我們針對這兩種引號舉個例子。為了理解上述語法,我們建立一個表。建立表的查詢如下 −

mysql> create table QuotesDemo
   -> (
   -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> UserName varchar(20),
   -> UserAge int
   -> );
Query OK, 0 rows affected (2.53 sec)

使用 insert 命令在表中插入一些記錄 −

mysql> insert into QuotesDemo(`UserName`,`UserAge`) values('John',23);
Query OK, 1 row affected (0.21 sec)
mysql> insert into QuotesDemo(`UserName`,`UserAge`) values('Carol',21);
Query OK, 1 row affected (0.24 sec)
mysql> insert into QuotesDemo(`UserName`,`UserAge`) values('Sam',22);
Query OK, 1 row affected (0.11 sec)

現在,你可以使用 select 語句顯示錶中的所有記錄。查詢如下 −

mysql> select *from `QuotesDemo`;

輸出

+----+----------+---------+
| Id | UserName | UserAge |
+----+----------+---------+
|  1 | John     |      23 |
|  2 | Carol    |      21 |
|  3 | Sam      |      22 |
+----+----------+---------+
3 rows in set (0.00 sec)

以下是顯示這兩種引號用法的查詢 −

mysql> select *from `QuotesDemo` where `UserName` = 'Carol';

輸出

+----+----------+---------+
| Id | UserName | UserAge |
+----+----------+---------+
|  2 | Carol    | 21      |
+----+----------+---------+
1 row in set (0.00 sec)

更新日期: 30-Jul-2019

231 次瀏覽

開啟您的職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.