Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_check_removable

  No additional text.


Syntax
create procedure sys.sp_check_removable @autofix varchar(4)
as
	declare @dbname sysname
	declare @exec_stmt nvarchar(max)
	declare @fgname sysname

	select @dbname=db_name()

	-- USE CORRECT non-dbo/guest CHECKING
	declare @ret int
	EXEC @ret = sys.sp_check_removable_sysusers @autofix
	if @ret <> 0
		return 1

	-- Run UPDATE STATISTICS on all user tables if there are no user defined filegroups
	if @autofix='auto' and
		(select count(*) from sysfilegroups) = 1
	begin
		select @exec_stmt = N'USE ' + quotename( @dbname , '[')
		+ N' EXEC sys.sp_updatestats '
		EXEC (@exec_stmt)
	end

	if (select count(*) from sysfilegroups) > 1
	begin
		if @autofix='auto'
		begin
			-- Mark any non-primary filegroups as READONLY
			DECLARE ms_crs_fg CURSOR LOCAL STATIC
			FOR SELECT groupname FROM sysfilegroups fg
				WHERE fg.groupid > 1 -- not primary
				AND fg.status & 0x8 = 0 -- not already readonly
				AND (SELECT count (*) FROM sysfiles f WHERE
				f.groupid = fg.groupid) > 0 -- has some files
			OPEN ms_crs_fg
			FETCH NEXT FROM ms_crs_fg INTO @fgname
			WHILE (@@FETCH_STATUS <> -1)
			BEGIN
				SELECT @exec_stmt = 'ALTER DATABASE '
				+ quotename( @dbname , '[')
				+ ' MODIFY FILEGROUP '
				+ quotename( @fgname , '[')
				+ ' READONLY'
				EXEC (@exec_stmt)
				FETCH NEXT FROM ms_crs_fg INTO @fgname
			END
			CLOSE ms_crs_fg
			DEALLOCATE ms_crs_fg
		end
		else
		begin
			if exists (SELECT groupname FROM sysfilegroups fg
				WHERE fg.groupid > 1 -- not primary
				AND fg.status & 0x8 = 0 -- not already readonly
				AND (SELECT count (*) FROM sysfiles f WHERE
				f.groupid = fg.groupid) > 0) -- has some files
			begin
				raiserror(15358,-1,-1)
				SELECT groupname FROM sysfilegroups fg
					WHERE fg.groupid > 1 -- not primary
					AND fg.status & 0x8 = 0 -- not already readonly
				return (-1)
			end
		end
	end
	return(0) -- sp_check_removable

 
Last revision 2008RTM
See also

  sp_certify_removable (Procedure)
sp_check_removable_sysusers (Procedure)
       



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