April 16, 2012

sp_attach_single_file_db (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_attach_single_file_db(nvarchar @dbname
, nvarchar @physname)

MetaData:

 create procedure sys.sp_attach_single_file_db  
@dbname sysname,
@physname nvarchar(260)
as
declare @execstring nvarchar (4000)
set nocount on

if (SERVERPROPERTY('IsMatrix') = 1)
begin
raiserror (28401, -1, -1, N'sys.sp_attach_single_file_db')
return (1)
end

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

select @execstring = 'CREATE DATABASE '
+ quotename( @dbname , '[')
+ ' ON (FILENAME ='
+ ''''
+ REPLACE(@physname,N'''',N'''''')
+ ''''
+ ' ) FOR ATTACH'
EXEC (@execstring)
if @@error <> 0
begin
-- No need to raiserror as the CREATE DATABASE will do so
return(1)
end

-- strip out replication from this database
EXEC sys.sp_MSremovedbreplication_internal @dbname

return (0) -- sp_attach_single_file_db

No comments:

Post a Comment

Total Pageviews