Scalar functions
回傳一個 value,且該 value 為 scalar datatype,不能回傳 text、ntext、image、cursor、timestamp 型別
SP 和 scalar functions 差在 SP 不能使用於SELECT
或WHERE
clause
To view the text of the function use
sp_helptext
FunctionName
EX.
|
參考連結
Inline table-valued functions
回傳一個 table,table 回傳的結構取決於SELECT
clause
因為SELECT
時是取得 underlying table,所以進行 DML 操作時可能會改到資料
使用時機
- Inline Table Valued functions can be used to achieve the functionality of parameterized views
JOIN
其他 table
EX.
|
Multistatement table-valued functions
效能
Inline table-valued functions 效能較 Multistatement table-valued functions 好
Internally, SQL Server treats an inline table valued function much like it would a view and treats a multi-statement table valued function similar to how it would a stored procedure.
EX.
|