Не вышел каменный цветок, враги подстраховались. :(
if object_id('tempdb..#test_shrinkfile') is null
exec('create procedure #test_shrinkfile as ')
GO
alter procedure #test_shrinkfile
as begin
set nocount on
set quoted_identifier, ansi_nulls, ansi_warnings, arithabort,
concat_null_yields_null, ansi_padding on
set numeric_roundabort off
declare
@trancount int = @@trancount
if @trancount > 0
rollback
dbcc shrinkfile(1)
while @@trancount < @trancount
begin tran
end
go
if object_id('tempdb..#t') is not null
drop table #t
create table #t(
DbId int
, FileId int
, CurrentSize int
, MinimumSize int
, UsedPages int
, EstimatedPages int
)
insert #t exec #test_shrinkfile
go
-------------------------------------------------------------------
Msg 3915, Level 16, State 0, Procedure #test_shrinkfile________________________________________________________________________________________________________0000AF5E, Line 13
Cannot use the ROLLBACK statement within an INSERT-EXEC statement.