来自 数据库 2020-03-08 02:33 的文章
当前位置: 网上澳门金莎娱乐 > 数据库 > 正文

验证SQL保留字

验证SQL保留字

SQL 是一门语言,而不是一个应用程序,也不是一个数据库。

SQL保留字验证

  • 检索单列
  • 检索多列
  • 检索所有列
  • 返回不同的值
  • 代码注释

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

关键字(keyword):SQL 里有保留字和非保留字之分。根据标准, 保留字是那些真正的关键字;决不能用它们做标识符。非保留字只是在特定的环境里有特殊的含义, 而在其它环境里是可以用做标识符的。大多数非保留字实际上都是 SQL 声明的内建表和函数的名字。 而非保留字的概念实质上只是用来表示在某些场合里,在一个字上附加了一些预先定义的含义。

mysql> select prod_name
    -> FROM Products;
+---------------------+
| prod_name           |
+---------------------+
| 8 inch teddy bear   |
| 12 inch teddy bear  |
| 18 inch teddy bear  |
| Fish bean bag toy   |
| Bird bean bag toy   |
| Rabbit bean bag toy |
| Raggedy Ann         |
| King doll           |
| Queen doll          |
+---------------------+
9 rows in set (0.00 sec)
  • SQL语句以分号(;)结束
  • 不区分大小写
  • 忽略空格

以上语句等同于:

  select prod_name FROM Products;

检索多列,列名以逗号(,)隔开:

mysql> select prod_name,prod_name,prod_price FROM Products;
+---------------------+---------------------+------------+
| prod_name           | prod_name           | prod_price |
+---------------------+---------------------+------------+
| 8 inch teddy bear   | 8 inch teddy bear   |       5.99 |
| 12 inch teddy bear  | 12 inch teddy bear  |       8.99 |
| 18 inch teddy bear  | 18 inch teddy bear  |      11.99 |
| Fish bean bag toy   | Fish bean bag toy   |       3.49 |
| Bird bean bag toy   | Bird bean bag toy   |       3.49 |
| Rabbit bean bag toy | Rabbit bean bag toy |       3.49 |
| Raggedy Ann         | Raggedy Ann         |       4.99 |
| King doll           | King doll           |       9.49 |
| Queen doll          | Queen doll          |       9.49 |
+---------------------+---------------------+------------+
9 rows in set (0.00 sec)

检索所有列:

mysql> select * FROM Products;
+---------+---------+---------------------+------------+-----------------------------------------------------------------------+
| prod_id | vend_id | prod_name           | prod_price | prod_desc                                                             |
+---------+---------+---------------------+------------+-----------------------------------------------------------------------+
| BR01    | BRS01   | 8 inch teddy bear   |       5.99 | 8 inch teddy bear, comes with cap and jacket                          |
| BR02    | BRS01   | 12 inch teddy bear  |       8.99 | 12 inch teddy bear, comes with cap and jacket                         |
| BR03    | BRS01   | 18 inch teddy bear  |      11.99 | 18 inch teddy bear, comes with cap and jacket                         |
| BNBG01  | DLL01   | Fish bean bag toy   |       3.49 | Fish bean bag toy, complete with bean bag worms with which to feed it |
| BNBG02  | DLL01   | Bird bean bag toy   |       3.49 | Bird bean bag toy, eggs are not included                              |
| BNBG03  | DLL01   | Rabbit bean bag toy |       3.49 | Rabbit bean bag toy, comes with bean bag carrots                      |
| RGAN01  | DLL01   | Raggedy Ann         |       4.99 | 18 inch Raggedy Ann doll                                              |
| RYL01   | FNG01   | King doll           |       9.49 | 12 inch king doll with royal garments and crown                       |
| RYL02   | FNG01   | Queen doll          |       9.49 | 12 inch queen doll with royal garments and crown                      |
+---------+---------+---------------------+------------+-----------------------------------------------------------------------+
9 rows in set (0.00 sec)

本文由网上澳门金莎娱乐发布于数据库,转载请注明出处:验证SQL保留字

关键词: