在MySQL查询中,表格和列周围的引号真的必要吗?
如果您的表名或列名是保留字,则需要在MySQL查询中在表名和列名两边使用引号。您需要对表名和列名使用反引号。语法如下:
SELECT *FROM `table` where `where`=condition;
这是创建不带带保留字引号的表的查询。由于它们是预定义的保留字,因此您会收到错误消息。错误如下:
mysql> create table table -> ( -> where int -> ); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table ( where int )' at line 1
现在让我们在表和列的名称周围加上引号,因为“表”和“位置”是保留字。这是带引号的查询:
mysql> create table `table` -> ( -> `where` int -> );
使用insert命令在表中插入记录。查询如下:
mysql> insert into `table`(`where`) values(1); mysql> insert into `table`(`where`) values(100); mysql> insert into `table`(`where`) values(1000);
在where条件的帮助下从表中显示特定记录。查询如下:
mysql> select *from `table` where `where`=100;
以下是输出:
+-------+ | where | +-------+ | 100 | +-------+ 1 row in set (0.00 sec)
热门推荐
10 爸妈简短婚礼祝福语大全
11 结婚词祝福语简短精辟
12 情人中秋祝福语简短
13 医院乔迁条幅祝福语简短
14 蛋糕话语简短毕业祝福语
15 作品棒棒哒祝福语简短
16 新娘贺词结婚祝福语简短
17 结婚祝福语简短大气古风
18 送给平辈生日祝福语简短