Glossary Of SQL

Basic Structure of SQL Server syntax

Intro

Generally speaking, the real difference between statements, clauses, batches, etc., is determined by how you use them at the time.
The Difference Between SQL Statement,Command, Clause, Batch, etc by Aubrey Love

🪧Note:日常工作中,这些术语的使用并不是很严格,不必纠结于此.但是了解这些术语的含义,帮助我们在阅读文档时更加准确的理解文档的含义.

个人对此的简单总结如下:

  • Statement:语句.是一条完整的 SQL 语句,可以是单行,也可以是多行。例如,SELECT * FROM Users; 就是一个 SQL 语句。通常用分号 ; 结尾。
  • Command:命令.通常指对数据库或数据库对象执行的操作。例如,CREATE, DROP, SELECT, INSERT, UPDATE, DELETE 等都是 SQL 命令。
  • Batch:批处理.这是一组 SQL 语句,它们作为一个单元一起发送到 SQL 服务器以便一起执行。在大多数 SQL 服务器中,批处理由一个或多个 SQL 语句组成,这些语句由分号 ; 分隔。
  • Clause:子句.这是 SQL 语句的一部分,它用于指定 SQL 语句的某些条件或修改 SQL 语句的行为。例如,WHERE, AND, OR, NOT, FROM, ORDER BY 等都是 SQL 子句。
  • Query : 查询.在 SQL 中,Query 是一个请求,用于从数据库中获取特定的数据。最常见的查询是 SELECT 语句,它用于从一个或多个表中选择数据。

SQL Statement

SQL Server “statements” are the most basic unit of code that can be executed in SQL Server.A statement is typically a single line of code, although multiple lines may be combined into a single statement. You can also use a semicolon (;) as a batch terminator that separates one command statement or batch from another.

SQL Command

Commands are often referred to as a STATEMENT or QUERY. However, a SQL command is any instruction set that directs SQL Server to perform an action against a given SQL Server object.

  • DDL (Data Definition Language)
  • DML (Data Manipulation Language)
  • DCL (Data Control Language)
  • TCL (Transaction Control Language)
  • ps: 有时把DML中的 SELECT 单独拿出来,称为 DQL(Data Query Language)
    DDL DML DCL TCL
    CREATE SELECT GRANT COMMIT
    ALTER INSERT REVOKE ROLLBACK
    DROP UPDATE SAVEPOINT
    TRUNCATE DELETE SET TRANSACTION
    COMMENT MERGE
    RENAME CALL
    EXPLAIN PLAN
    LOCK TABLE

SQL Batch

A SQL Server “batch” is a single or multi-line block of code that tells the SQL Server what action to take on a SQL Server object. Batches are typically separated by the “GO” statement at the end of a SQL query;

1
2
3
4
5
6
7
8
USE AdventureWorks2019;
GO
SELECT \*
FROM HumanResources.Department;
GO
SELECT \*
FROM HumanResources.Employee;
GO

SQL Query

The “query” keyword in SQL Server is used to perform an action against a database or database object.

SQL Clause

A SQL Server “clause” is a code element that defines a particular action. Clauses are typically used to control the flow of a query or Transact-SQL program.

The most common clauses are the FROM, WHERE, and ORDER BY clauses. The SELECT clause is used to specify the columns or expressions that will be returned by a query.

DataBase Glossary

Database,Schema:数据库,一个库可以有多个表
Table,Relation:表(Table)是数据库中存储数据的主要结构,它由行(记录)和列(字段)组成.表的结构通常由字段名和字段类型定义
Row,Record,Item,Tuple:行,一行可以有很多列;
Column,Field,列,不再细分的具体值

References

⭐www.mssqltips.com
www.databasestar.com
dev.mysql.com

Author

Efterklang

Posted on

2024-01-26

Updated on

2024-09-18

Licensed under

Comments