ใน 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)
แทรกข้อมูล:
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)แสดงข้อมูลทั้งหมด:
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)