顯示具有 SQL-StoredProc、Triggers、Views 標籤的文章。 顯示所有文章
顯示具有 SQL-StoredProc、Triggers、Views 標籤的文章。 顯示所有文章

2013年5月21日 星期二

User Defined Functions

Functions are programmable objects that are used to perform calculations that can be returned to a calling application or integrated into a result set. Functions can access data and return results, but they cannot make any modifications.

You can create your own functions, referred to as user-defined functions, and store the functions in any database for which you have CREATE FUNCTION authority.

2013年5月16日 星期四

Views

檢視(VIEW) 同時也稱為虛擬資料表,它將一連串複雜的 SELECT 陳述式組合成一個虛擬資料表,可以用來簡化日後的查詢操作。 除了這個優點,你也可以透過 VIEW 來更新資料。此外,若搭配使用索引檢視(Indexed View)還可以用來提升查詢效能。

Trigger

TRIGGER 是一種特殊的預存程序,雖然也是由使用者自訂的可程式化物件,但是它不可以直接被使用者執行。 它必須建構在 table 或 view 的特定事件中,如:INSERT, UPDATE, DELETE。 當這些事件發生時,才會自動引發 TRIGGER 執行。

Cursor

SQL Server is built to process sets of data. However, there are times when you need to process data one row at a time. The result of a SELECT statement is returned to a server-side object called a cursor, which allows you to access one row at a time within the result set and even allows scrolling forward as well as backward through the result set.

預存程序的錯誤處理

Stored Procedures

The first time that a stored procedure is accessed, SQL Server generates compile and execution plans that are stored in the query cache and reused for subsequent executions. Therefore, you can receive a slight performance benefit when using a stored procedure by avoiding the need to parse, compile, and generate a query plan on subsequent executions of a stored procedure.