Transact-SQL 语句Transact-SQL statements

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database 是Azure SQL 托管实例Azure SQL Managed InstanceYesAzure SQL 托管实例Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是并行数据仓库Parallel Data Warehouseyes并行数据仓库Parallel Data Warehouse适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database 是Azure SQL 托管实例Azure SQL Managed InstanceYesAzure SQL 托管实例Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是并行数据仓库Parallel Data Warehouseyes并行数据仓库Parallel Data Warehouse

SQL 语句是工作的原子单元,要么完全成功,要么完全失败。A SQL statement is an atomic unit of work and either completely succeeds or completely fails. SQL 语句是一组指令,由标识符、参数、变量、名称、数据类型和成功编译的 SQL 保留字组成。A SQL statement is a set of instruction that consists of identifiers, parameters, variables, names, data types, and SQL reserved words that compiles successfully. 如果 BeginTransaction 命令未指定启动事务,Analysis ServicesAnalysis Services 会为 SQL 语句创建隐式事务。Analysis ServicesAnalysis Services creates an implicit transaction for a SQL statement if a BeginTransaction command does not specify the start of a transaction. 如果此语句成功,Analysis ServicesAnalysis Services 会始终提交隐式事务;如果此命令失败,则会回滚隐式事务。Analysis ServicesAnalysis Services always commits an implicit transaction if the statement succeeds, and rolls back an implicit transaction if the command fails.

语句有很多种类型。There are many types of statements. 也许最重要的是 SELECT,它从数据库中检索行,并支持从 SQL ServerSQL Server 中的一个或多个表内选择一个或多个行或列。Perhaps the most important is the SELECT that retrieves rows from the database and enables the selection of one or many rows or columns from one or many tables in SQL ServerSQL Server. 本文总结了除 SELECT 语句外还用于 Transact-SQL (T-SQL) 的语句类别。This article summarizes the categories of statements for use with Transact-SQL (T-SQL) in addition to the SELECT statement. 左侧导航栏中列出了所有语句。You can find all of the statements listed in the left-hand navigation.

备份和还原Backup and restore

备份和还原语句提供创建备份和从备份中还原的方法。The backup and restore statements provide ways to create backups and restore from backups. 有关详细信息,请参阅备份和还原概述For more information, see the Backup and restore overview.

数据定义语言Data Definition Language

数据定义语言 (DDL) 语句定义数据结构。Data Definition Language (DDL) statements defines data structures. 使用以下语句在数据库中创建、更改或删除数据结构。Use these statements to create, alter, or drop data structures in a database. 这些语句包括:These statements include:

  • ALTERALTER
  • 排序规则Collations
  • CREATECREATE
  • DROPDROP
  • DISABLE TRIGGERDISABLE TRIGGER
  • ENABLE TRIGGERENABLE TRIGGER
  • RENAMERENAME
  • UPDATE STATISTICSUPDATE STATISTICS
  • TRUNCATE TABLETRUNCATE TABLE

数据操作语言Data Manipulation Language

数据操作语言 (DML) 影响存储在数据库中的信息。Data Manipulation Language (DML) affect the information stored in the database. 使用以下语句在数据库中插入、更新和更改行。Use these statements to insert, update, and change the rows in the database.

  • BULK INSERTBULK INSERT
  • DELETEDELETE
  • INSERTINSERT
  • SELECTSELECT
  • UPDATEUPDATE
  • MERGEMERGE

权限语句Permissions statements

权限语句决定哪些用户和登录名可以访问数据并执行操作。Permissions statements determine which users and logins can access data and perform operations. 有关身份验证和访问权限的详细信息,请参阅安全中心For more information about authentication and access, see the Security center.

Service Broker 语句Service Broker statements

Service Broker 是一项功能,可为消息和队列应用程序提供本机支持。Service Broker is a feature that provides native support for messaging and queuing applications. 有关详细信息,请参阅 Service BrokerFor more information, see Service Broker.

会话设置Session settings

SET 语句决定当前会话处理运行时设置的方式。SET statements determine how the current session handles run time settings. 如需查看概述,请参阅 SET 语句For an overview, see SET statements.