April 22, 2012

sp_dropuser (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_dropuser(nvarchar @name_in_db)

MetaData:

 create procedure sys.sp_dropuser  
@name_in_db sysname -- user name to drop
as
-- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
set nocount on
declare @ret int
declare @targetName sysname
-- LIMIT TO SQL/NT USERS (BCKWRD COMPAT ONLY!)
if not exists (select * from sysusers where name = @name_in_db
and (isntuser = 1 or isntname = 0))
begin
raiserror(15008,-1,-1,@name_in_db)
return (1)
end
-- store target name
select @targetName = (select sl.name from master..syslogins sl,sysusers su where su.name = @name_in_db and su.sid = sl.sid)

-- DROP THE USER FROM THE DATABASE --
EXEC @ret = sys.sp_revokedbaccess @name_in_db
if @ret <> 0
begin
-- AUDIT FAILED SECURITY CHECK
dbcc auditevent (109, 2, 0, @targetName, @name_in_db, NULL, NULL, NULL, NULL, NULL)
return (1)
end

-- AUDIT SUCCESSFUL SECURITY CHECK --
dbcc auditevent (109, 2, 1, @targetName, @name_in_db, NULL, NULL, NULL, NULL, NULL)

-- FINALIZATION: PRINT/RETURN SUCCESS --
return (0) -- sp_dropuser

No comments:

Post a Comment

Total Pageviews