Transact-SQL 陳述式Transact-SQL statements

適用範圍:Applies to: 是SQL ServerSQL Server (所有支援的版本) yesSQL ServerSQL Server (all supported versions) 是Azure SQL DatabaseAzure SQL DatabaseYesAzure SQL DatabaseAzure 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 DatabaseAzure SQL DatabaseYesAzure SQL DatabaseAzure 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. 此文章摘要說明用於 Transact-SQL (T-SQL) (除了 SELECT 陳述式之外) 的類別。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

BACKUP 及 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
  • 刪除DELETE
  • 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.