教學課程:撰寫 Transact-SQL 陳述式Tutorial: Writing Transact-SQL Statements

適用於: 是SQL Server 是Azure SQL Database 是Azure SQL 資料倉儲 是平行處理資料倉儲 APPLIES TO: yesSQL Server yesAzure SQL Database yesAzure SQL Data Warehouse yesParallel Data Warehouse

歡迎使用「撰寫 Transact-SQLTransact-SQL 陳述式」教學課程。Welcome to the Writing Transact-SQLTransact-SQL Statements tutorial. 本教學課程的主要對象是撰寫 SQL 陳述式的新手,This tutorial is intended for users who are new to writing SQL statements. 會透過檢閱一些建立資料表及插入資料的基本陳述式,協助新手上路。It will help new users get started by reviewing some basic statements for creating tables and inserting data. 本教學課程採用 Transact-SQLTransact-SQL,是 SQL 標準的 MicrosoftMicrosoft 實作。This tutorial uses Transact-SQLTransact-SQL, the MicrosoftMicrosoft implementation of the SQL standard. 本教學課程的目的是用來概述 Transact-SQLTransact-SQL 語言,而非用來取代 Transact-SQLTransact-SQL 類別。This tutorial is intended as a brief introduction to the Transact-SQLTransact-SQL language and not as a replacement for a Transact-SQLTransact-SQL class. 在本教學課程中的陳述式是有意經過簡化的,並無意呈現一般實際資料庫中所遇到的複雜問題。The statements in this tutorial are intentionally simple, and are not meant to represent the complexity found in a typical production database.

注意: 如果您是初學者,可能會覺得使用 SQL Server Management StudioSQL Server Management Studio 反而比撰寫 Transact-SQLTransact-SQL 陳述式更簡單。NOTE: If you are a beginner you might find it easier to use SQL Server Management StudioSQL Server Management Studio instead of writing Transact-SQLTransact-SQL statements.

尋找詳細資訊Finding More Information

若要尋找任何特定陳述式的詳細資訊,請在《SQL Server 線上叢書》中依名稱搜尋陳述式,或是使用 [內容] 瀏覽 Transact-SQL 參考 (Database Engine) 底下依字母順序排列的 1,800 個語言元素。To find more information about any specific statement, either search for the statement by name in SQL Server Books Online, or use the Contents to browse the 1,800 language elements listed alphabetically under Transact-SQL Reference (Database Engine). 此外,搜尋與您有興趣的主題內容相關的關鍵字,也是另一種找出資訊的不錯方式。Another good strategy for finding information is to search for key words that are related to the subject matter you are interested in. 例如,您想要知道如何傳回一部分的日期 (如月份),您可以搜尋 dates [SQL Server] 的索引,然後選取 datepartsFor example, if you want to know how to return a part of a date (such as the month), search the index for dates [SQL Server], and then select dateparts. 即會帶您前往 DATEPART (Transact-SQL) 主題。This takes you to the topic DATEPART (Transact-SQL). 例如若要找出如何使用字串,您可以搜尋字串函數As another example, to find out how to work with strings, search for string functions. 即會帶您前往字串函數 (Transact-SQL) 主題。This takes you to the topic String Functions (Transact-SQL).

學習內容What You Will Learn

本教學課程會示範如何建立資料庫、在資料庫中建立資料表、插入資料至資料表、更新資料、讀取資料、刪除資料,然後刪除資料表。This tutorial shows you how to create a database, create a table in the database, insert data into the table, update the data, read the data, delete the data, and then delete the table. 您將建立檢視和預存程序,並將使用者設定到資料庫及資料。You will create views and stored procedures and configure a user to the database and the data.

本教學課程分成三個課程:This tutorial is divided into three lessons:

第 1 課:建立資料庫物件Lesson 1: Creating Database Objects
在這一課,您會建立資料庫、在資料庫中建立資料表、插入資料至資料表、更新資料以及讀取資料。In this lesson, you create a database, create a table in the database, insert data into the table, update the data, and read the data.

第 2 課:設定資料庫物件的權限Lesson 2: Configuring Permissions on Database Objects
在這一課,您會建立登入及使用者,In this lesson, you create a login and user. 也會建立檢視和預存程序,然後將使用者權授與預存程序。You will also create a view and a stored procedure, and then grant the user permission to the stored procedure.

第 3 課:刪除資料庫物件Lesson 3: Deleting Database Objects
在這一課,您會移除資料的存取、從資料表中刪除資料、刪除資料表,最後刪除資料庫。In this lesson, you remove access to data, delete data from a table, delete the table, and then delete the database.

需求Requirements

為了完成本教學課程,您並不需要精通 SQL 語言,但必須了解基本資料庫概念 (如資料表)。To complete this tutorial, you do not have to know the SQL language, but you should understand basic database concepts such as tables. 在進行本教學課程期間,您將建立資料庫以及建立 Windows 使用者。During this tutorial, you will create a database and create a Windows user. 這些工作需要高層權限,因此您必須以系統管理員的身份登入電腦。These tasks require a high level of permissions; therefore, you should log in to the computer as an administrator.

另外,系統必須有安裝下列程式:Your system must have the following installed: