我添加了一个表值函数:
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
并执行了alter函数。但是,当我再次在Management Studio中打开TVF时,上面的行不会出现,因为它已被删除。这是设计还是我做错了什么?
这是我试图用上述隔离级别保存的表值函数。
USE [playerspace]
GO
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
/****** Object: UserDefinedFunction [dbo].[udf_get_games_by_date_league_id_group_id] Script Date: 3/21/2015 8:59:32 AM ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER FUNCTION [dbo].[udf_get_games_by_date_league_id_group_id]
(@league_id int, @group_id int,
@division_id int, @tournament_division_id int,
@season_id int, @date1 datetime, @date2 datetime)
RETURNS TABLE
AS
RETURN
WITH events_by_date_CTE (event_type, str_event_address, str_event_title, str_event_description, str_event_location, f_score_set_by, int_game_status, f_home_team_id, f_group_id, f_visitor_team_id, f_season_id, f_league_id, f_member_id, p_event_id, f_division_id, int_visitor_team_score, int_home_team_score, f_zipcode_id, dte_event_start, dte_event_end, gamedaypart, gameday, tme_event_start, f_play_location_id, f_league_schedule_id, f_tournament_division_id, f_play_location_time_slot_id, str_location_name, str_event_address_linked, str_cityname_linked, str_zipcode_linked, str_statecode_linked, str_preferredcityname, str_cityname, str_zipcode, str_statename, str_statecode, visitorgroupurl, str_league_name, str_league_url, str_group_url, int_organization_type, homegroupurl, visitorteamname, hometeamname, str_group_name,int_lon,int_lat,str_division,str_tournament_division,str_season,admin_list,int_timeslot_length_in_minutes,zonename,zoneabbrev,zonegmtoffset,zonedst,zonename_linked,zoneabbrev_linked,zonegmtoffset_linked,zonedst_linked)
AS
-- Define the CTE query.
(
select event_type,str_event_address,str_event_title,str_event_description,str_event_location,f_score_set_by,int_game_status,f_home_team_id,f_group_id,f_visitor_team_id,f_season_id,f_league_id,f_member_id,p_event_id,f_division_id,int_visitor_team_score,int_home_team_score,f_zipcode_id,dte_event_start,dte_event_end,gamedaypart,gameday,tme_event_start,f_play_location_id,f_league_schedule_id,f_tournament_division_id,f_play_location_time_slot_id,str_location_name,str_event_address_linked,str_cityname_linked,str_zipcode_linked,str_statecode_linked,str_preferredcityname,str_cityname,str_zipcode,str_statename,str_statecode,visitorgroupurl,str_league_name,str_league_url,str_group_url,int_organization_type,homegroupurl,visitorteamname,hometeamname,str_group_name,int_lon,int_lat,str_division,str_tournament_division,str_season,admin_list,int_timeslot_length_in_minutes,zonename,zoneabbrev,zonegmtoffset,zonedst,zonename_linked,zoneabbrev_linked,zonegmtoffset_linked,zonedst_linked
from udf_get_events_by_date_group_id_league_id(@league_id,@group_id,@division_id,@tournament_division_id,@season_id,@date1,@date2)
)
(
select * from events_by_date_CTE as games_query
where 1=1
)
GO
答案 0 :(得分:1)
非常奇怪,但让我们做一个测试......
程序定义
CREATE PROCEDURE Test_Procs
AS
BEGIN
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SELECT 'Test_Procs executed'
END
检查程序定义
exec sp_helptext 'Test_Procs'
程序定义
It returns exactly the same definition as above.
答案 1 :(得分:1)
在这种情况下,SET运算符不是UDF的一部分。 此外,您不能在UDF&#39>中使用SET运算符
https://msdn.microsoft.com/en-us/library/ms191320.aspx
用户定义的函数不能用于执行修改操作 数据库状态。
用户定义的函数不能包含OUTPUT 以表为目标的INTO子句。
用户定义的函数可以 不返回多个结果集。如果需要,请使用存储过程 返回多个结果集。
错误处理受限于 用户定义的功能。
UDF不支持TRY ... CATCH,@ ERROR或 RAISERROR。
用户定义的函数无法调用存储过程,但是 可以调用扩展存储过程。
用户定义的功能不能 使用动态SQL或临时表。允许使用表变量。
用户定义的函数中不允许使用SET语句。
- 醇>
FOR XML 不允许使用
看看子弹8。