June 8, 2012

sp_resetstatus (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_resetstatus(nvarchar @DBName)

MetaData:

   
create procedure sys.sp_resetstatus -- 1995/11/30 14:12 #12092
@DBName sysname
as
set nocount on
declare @state int
declare @source_dbid int

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

-- RESTRICT TO SA --
if (not (is_srvrolemember('sysadmin') = 1))
begin
raiserror(15247,-1,-1)
return (1)
end

-- FORBID ACTIVE TXN --
set implicit_transactions off
if @@trancount > 0
begin
raiserror(15002,-1,-1,'sys.sp_resetstatus')
return (1)
end

--
-- Make sure the db exists
--
if not exists (select * from master.sys.databases where name = @DBName)
begin
raiserror(15010,-1,-1,@DBName)
return (1)
end

select @state = state,
@source_dbid = source_database_id
from master.sys.databases
where name = @DBName

--
-- Cannot reset a database snapshot. Anything but NULL or 0
-- is a snapshot.
--
if (ISNULL(@source_dbid, 0) <> 0)
begin
raiserror(15658,-1,-1)
return (1)
end

--
-- Must already be suspect. 4 is SUSPECT state.
--
if (@state <> 4)
begin
raiserror(15056,-1,-1,@DBName)
return (1)
end

-- Note: database @DBName may not exist anymore
-- If invoke gets error, exception will abort this proc.
EXEC %%DatabaseRef(Name = @DBName).SetSuspect(Value = 0)

-- Warning: You must recover this database prior to access.
raiserror(15074,-1,-1)

return (0) -- sp_resetstatus

No comments:

Post a Comment

Total Pageviews