Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_attach_db

  No additional text.


Syntax
create procedure sys.sp_attach_db
	@dbname sysname
	, @filename1 nvarchar(260)
	, @filename2 nvarchar(260) = NULL
	, @filename3 nvarchar(260) = NULL
	, @filename4 nvarchar(260) = NULL
	, @filename5 nvarchar(260) = NULL
	, @filename6 nvarchar(260) = NULL
	, @filename7 nvarchar(260) = NULL
	, @filename8 nvarchar(260) = NULL
	, @filename9 nvarchar(260) = NULL
	, @filename10 nvarchar(260) = NULL
	, @filename11 nvarchar(260) = NULL
	, @filename12 nvarchar(260) = NULL
	, @filename13 nvarchar(260) = NULL
	, @filename14 nvarchar(260) = NULL
	, @filename15 nvarchar(260) = NULL
	, @filename16 nvarchar(260) = NULL

as
	declare @execstring nvarchar (max)
	set nocount on

	if ((@dbname is null or datalength(@dbname) = 0) or
	    (@filename1 is null or datalength(@filename1) = 0))
	begin
		raiserror (15004,-1,-1)
		return (1)
	end

	-- build initial CREATE DATABASE
	select @execstring = 'CREATE DATABASE '
		+ quotename( @dbname , '[')
		+ ' ON (FILENAME ='
		+ ''''
		+ REPLACE(@filename1,N'''',N'''''')
		+ ''''

	-- add any additional files

	if (@filename2 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename2 ,N'''',N'''''')
			+ ''''
	end

	if (@filename3 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename3 ,N'''',N'''''')
			+ ''''
	end

	if (@filename4 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename4 ,N'''',N'''''')
			+ ''''
	end

	if (@filename5 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename5 ,N'''',N'''''')
			+ ''''
	end

	if (@filename6 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename6 ,N'''',N'''''')
			+ ''''
	end

	if (@filename7 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename7 ,N'''',N'''''')
			+ ''''
	end

	if (@filename8 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename8  ,N'''',N'''''')
			+ ''''
	end

	if (@filename9 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename9 ,N'''',N'''''')
			+ ''''
	end

	if (@filename10 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename10  ,N'''',N'''''')
			+ ''''
	end

	if (@filename11 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename11  ,N'''',N'''''')
			+ ''''
	end

	if (@filename12 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename12  ,N'''',N'''''')
			+ ''''
	end

	if (@filename13 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename13  ,N'''',N'''''')
			+ ''''
	end

	if (@filename14 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename14  ,N'''',N'''''')
			+ ''''
	end

	if (@filename15 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename15 ,N'''',N'''''')
			+ ''''
	end

	if (@filename16 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename16  ,N'''',N'''''')
			+ ''''
	end


	-- note it as for attach
	select @execstring = @execstring + ' ) FOR ATTACH'

	EXEC (@execstring)

	-- No need to raiserror as the CREATE DATABASE will do so
	if @@error <>  0
		return(1)

	return (0) -- sp_attach_db

 
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