April 17, 2012

sp_clean_db_free_space (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_clean_db_free_space(nvarchar @dbname
, int @cleaning_delay)

MetaData:

   
create proc sys.sp_clean_db_free_space (@dbname sysname, @cleaning_delay int = 0)
as
begin
SET NOCOUNT ON
declare @quoted_dbname nvarchar(258)
set @quoted_dbname=QUOTENAME(@dbname)
--
-- Parameter check
-- @dbname
--
if (db_id(@dbname) is null)
begin
RAISERROR(15010, 16, -1, @quoted_dbname)
return (1)
end

--
-- security check
-- only db_owner can execute this
--
declare @check nvarchar(1024)
set @check = 'USE ' + @quoted_dbname +
'if (is_member (''db_owner'') != 1)
begin
raiserror(14260, 16, -1)
end'

exec (@check)
if @@error =14260
begin
return (1)
end

create table #cleanfiles (fileid int)
declare @sql as nvarchar(1024)
set @sql = 'insert #cleanfiles (fileid) select file_id from ' + @quoted_dbname + '.sys.database_files where type = 0'
exec (@sql)

declare @file int
set @file = 1
while @file is not null
begin
exec sp_clean_db_file_free_space @dbname, @file, @cleaning_delay

select @file = min(fileid) from #cleanfiles where fileid > @file
end

drop table #cleanfiles

return (0)
end

No comments:

Post a Comment

Total Pageviews