Transact-SQL 語言設計教學

Download Report

Transcript Transact-SQL 語言設計教學

Transact-SQL 語言設計教學
Module 1
Introduction To Transact SQL
◆Types of Transact-SQL Statements
Data Definition Language



CREATE object_name
ALTER object_name
DROP object_name
Data Control Language



GRANT
DENY
REVOKE
Data Manipulation Language




SELECT
INSERT
UPDATE
DELETE
◆Transact-SQL Syntax Elements
Types Of Data
Variables
System Functions
Operators
Control-of-Flow Language Elements
Reserved Keywords
Batch Directives
Types Of Data
Numbers
Dates
Characters
Binary
Image and Text
Table
SQL Variants
Cursor
User-defined
Uniqueidentifier
Variables
使用者自訂變數以DECLARE宣告
變數名稱以@開頭
以SET或SELECT指定變數值
變數有區域限制
請勿使用兩個@@,此為系統變數。列如@@error
System Functions
Aggregate Functions


統計函數用以計算資料的數值,例如平均值,總計值等等
統計函數除了Count(*)之外,其他統計函數會自動忽略null值
Scalar Functions

對單一值運算然後傳回單一值。無論運算式是否為有效,純量函數
皆可使用。
Rowset Functions

可用於 SQL 陳述式中的資料表參考
Operators
數字運算元

+ - * /
%
比較運算元


= > < >= <= <>
不要使用!=
邏輯運算元

AND OR NOT
字串運算元

+
Control-of-Flow Language Elements
Statement Level



If …..Else
Begin…..End
While constructs
Row Level

CASE function
Reserved Keywords
Batch Directives