SQL 基础
SQL 简介
SQL 入门
SQL 语法
SQL 创建数据库
SQL 创建表
SQL Constraints
SQL Insert
SQL Select
SQL Where
SQL AND & OR
SQL IN & Between
SQL Order By
SQL Top/Limit
SQL Distinct
SQL Update
SQL Delete
SQL Truncate Table
SQL Drop
SQL 连接
SQL Joining Tables
SQL Inner Join
SQL Left Join
SQL Right Join
SQL Full Join
SQL Cross Join
高级 SQL
SQL Union
SQL Like
SQL Alter Table
SQL Aliases
SQL Group By
SQL Having
SQL Create View
SQL Create Index
SQL Dates and Times
SQL Cloning Tables
SQL 临时表
SQL 子查询
SQL 注入
SQL 参考
SQL 数据类型
MySQL 数据类型
SQL Server 数据类型
SQL 方法
SQL 语法 - SQL基础教程 - 笔下光年
网站首页
SQL 语法
The syntax of SQL is governed by the American National Standards Institute (ANSI) and the International Organization for Standardization (ISO). ## SQL Statements SQL statements are very simple and straightforward like plain English but with specific syntax. An SQL statement is composed of a sequence of keywords, identifiers, etc. terminated by a semicolon (`;`). Here is an example of a valid SQL statement. ```sql SELECT emp_name, hire_date, salary FROM employees WHERE salary > 5000; ``` For better readability you can also write the same statement, as follow: ```sql SELECT emp_name, hire_date, salary FROM employees WHERE salary > 5000; ``` Use semicolon at the end of an SQL statement — it terminates the statement or submits the statement to the database server. Some database management system has, however, no such requirement, but it is considered as a best practice to use it. We'll discuss each part of these statements in detail in upcoming chapters. <div class="callout callout-info mb-3">Note: Any number of line breaks may occur within a SQL statement, provided that any line break does not break off keywords, values, expression, etc.</div> ## Case Sensitivity in SQL Consider another SQL statement that retrieves the records from employees table: ```sql SELECT emp_name, hire_date, salary FROM employees; ``` The same statement can also be written, as follow: ```sql select emp_name, hire_date, salary from employees; ``` SQL keywords are case-insensitive that means `SELECT` is same as `select`. But, the database and table names may case-sensitive depending on the operating system. In general, Unix or Linux platforms are case-sensitive, whereas Windows platforms aren't. <div class="callout callout-success mb-3">Tip: It is recommended to write the SQL keywords in uppercase, to differentiate it from other text inside a SQL statement for a better understanding.</div> ## SQL Comments A comment is simply a text that is ignored by the database engine. Comments can be used to provide a quick hint about the SQL statement. SQL support single-line as well as multi-line comments. To write a single-line comment start the line with two consecutive hyphens (`--`). For example: ```sql -- Select all the employees SELECT * FROM employees; ``` However to write multi-line comments, start the comment with a slash followed by an asterisk (`/*`) and end the comment with an asterisk followed by a slash (`*/`), like this: ```sql /* Select all the employees whose salary is greater than 5000 */ SELECT * FROM employees WHERE salary > 5000; ```
上一篇:
SQL 入门
下一篇:
SQL 创建数据库