Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_clean_db_free_space

  No additional text.


Syntax

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

 
Last revision 2008RTM
News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash