Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_detach_db

  No additional text.


Syntax
create procedure sys.sp_detach_db
	@dbname sysname = null,
	@skipchecks nvarchar(10) = null,
	@keepfulltextindexfile nvarchar(10) = null
as
	declare @dbid int
	declare @exec_stmt nvarchar(4000)

	if @dbname is null
	begin
		raiserror(15354,-1,-1)
		return(1)
	end

	if lower(@skipchecks) <> N'true'
		and lower(@skipchecks) <> N'false'
		and @skipchecks is not null
	begin
		raiserror(15354,-1,-1)
		return(1)
	end

	if	@keepfulltextindexfile is not null
		and lower(@keepfulltextindexfile) <> N'true'
		and lower(@keepfulltextindexfile) <> N'false'
	begin
		raiserror(15354,-1,-1)
		return(1)
	end

	select @dbid = dbid from master.dbo.sysdatabases where name=@dbname
	if @dbid is null
	begin
		raiserror(15010,-1,-1,@dbname)
		return(1)
	end

	-- make sure not trying to detach within a transaction
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_detach_db')
		return(1)
	end

	-- run UPDATE STATISTICS on all tables in the database so they are current
	-- when transferred to READONLY media
	if lower(@skipchecks) <> N'true'
	begin
		select @exec_stmt = 'USE ' + quotename( @dbname , '[')
			+ ' EXEC sys.sp_updatestats ''RESAMPLE'' '
		EXEC (@exec_stmt)
	end


	if @keepfulltextindexfile is null
	begin
		select @exec_stmt = 'DBCC DETACHDB ('
				+ quotename( @dbname , '[')
				+ ')'
	end
	else
	begin
		if lower(@keepfulltextindexfile) <> N'true'
		begin
			select @exec_stmt = 'DBCC DETACHDB ('
					+ quotename( @dbname , '[')
					+ ', 0 )'
		end
		else
		begin
		select @exec_stmt = 'DBCC DETACHDB ('
				+ quotename( @dbname , '[')
				+ ', 1 )'
		end
	end

	EXEC (@exec_stmt)
	return (0) -- sp_detach_db

 
Last revision 2008RTM
See also

  sp_copysubscription (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