April 18, 2012

sp_dropdevice (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_dropdevice(nvarchar @logicalname
, varchar @delfile)

MetaData:

 create procedure sys.sp_dropdevice -- - 1996/04/08 00:00  
@logicalname sysname, -- logical name of the device
@delfile varchar(7) = null -- optional param. to delete disk file
as
declare @delfileIn varchar(7)
select @delfileIn = @delfile
-- See if user specified something for @delfile and, if so, validate it.
if @delfile is not null
begin
select @delfile = lower(@delfile collate Latin1_General_CI_AS)
if @delfile <> 'delfile'
begin
raiserror(15216,-1,-1,@delfileIn)
return(1)
end
end

-- If we're in a transaction, disallow this since it might make recovery impossible.
set implicit_transactions off
if @@trancount > 0
begin
raiserror(15002,-1,-1,'sys.sp_dropdevice')
return (1)
end

-- Only the system administrator (SA) can run this command.
-- Check to make sure the executor is the sa.
if not is_srvrolemember('diskadmin') = 1
begin
raiserror(15247,-1,-1)
return (1)
end

-- Check and make sure that the device actually exists.
if not exists (select * from master.dbo.sysdevices where name = @logicalname)
begin
raiserror(15012,-1,-1,@logicalname)
return (1)
end

-- Drop the device.
if @delfile = 'delfile'
dbcc dbrepair
('', 'dropdevice',@logicalname, 1) WITH NO_INFOMSGS
else
dbcc dbrepair
('', 'dropdevice',@logicalname, 0) WITH NO_INFOMSGS

if @@error <> 0
return (1)

raiserror(15463,-1,-1)

return (0) -- sp_dropdevice

No comments:

Post a Comment

Total Pageviews