多语句表值函数与内联表值函数对比

来源:互联网 发布:java文件管理系统源码 编辑:程序博客网 时间:2024/06/08 14:15
注:内联表值函数性能更好,能做成 内联表值函数 的,不要做成 多语句表值函数
 原表值函数(多语句)优化后的表值函数(内联)SQL
-- =============================================-- Author:<Author,,Name>-- Create date: <Create Date,,>-- Description:<Description,,>-- =============================================CREATE FUNCTION <Inline_Function_Name, sysname, FunctionName> (-- Add the parameters for the function here<@param1, sysname, @p1> <Data_Type_For_Param1, , int>, <@param2, sysname, @p2> <Data_Type_For_Param2, , char>)RETURNS TABLE ASRETURN (-- Add the SELECT statement with parameter references hereSELECT 0)GO

-- =============================================-- Author:<Author,,Name>-- Create date: <Create Date,,>-- Description:<Description,,>-- =============================================CREATE FUNCTION <Table_Function_Name, sysname, FunctionName> (-- Add the parameters for the function here<@param1, sysname, @p1> <data_type_for_param1, , int>, <@param2, sysname, @p2> <data_type_for_param2, , char>)RETURNS <@Table_Variable_Name, sysname, @Table_Var> TABLE (-- Add the column definitions for the TABLE variable here<Column_1, sysname, c1> <Data_Type_For_Column1, , int>, <Column_2, sysname, c2> <Data_Type_For_Column2, , int>)ASBEGIN-- Fill the table variable with the rows for your result setRETURN ENDGO

消耗毫秒(加索引前)2003207消耗毫秒(加索引后)9377

0 0
原创粉丝点击