>>WITH RESULT SETS

 

為預存程序提供一個很好的功能,可明確定義資料集中各欄位型態。 避免預存程序執行過程中被變更欄位屬性。

In earlier versions of SQL server when we wished to change a column name or datatype in the resultset of a stored procedure, all the references needed to be changed. There was no simple way to dump the output of a stored procedure without worrying about the column names and data types.

 

CREATE PROCEDURE Denali_WithResultSet
 
AS
 BEGIN 
 SELECT 1 as No,'Tsql' Type, 'WithResultSet' AS Feature UNION ALL 
       SELECT 2 as No,'Tsql' Type, 'Throw' AS Feature UNION ALL 
       SELECT 3 as No,'Tsql' Type, 'Offset'AS Feature UNION ALL 
       SELECT 4 as No,'Tsql' Type, 'Sequence' AS Feature 
END
 
使用下列語法執行預存程序
EXEC Denali_WithResultSet 
WITH RESULT SETS
 (
       (      No int,
              FeatureType varchar(50),
              FeatureName varchar(50)
        )  
)
明確的定義資料集中個欄位的資料型態,可讓前端程式接收時不易發生錯誤

 

 

參考:New T-SQL Features in SQL Server 2012

arrow
arrow
    全站熱搜

    小草 發表在 痞客邦 留言(0) 人氣()