Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_droprolemember

  No additional text.


Syntax
create procedure sys.sp_droprolemember
	@rolename       sysname,
	@membername     sysname
AS
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES 
	set nocount on
	declare @roluid     int,
            @owner      int,
            @memuid     int,
            @ret        int

    -- Was a part of check to prevent inside a user Xact. Leave for backward compat.
	set implicit_transactions off

	--cannot change membership of public
	if @rolename = 'public'
	begin
		raiserror(15081, -1,-1)
		return(1)
	end

	BEGIN TRANSACTION

	-- SHARE LOCK ROLE 
	EXEC %%Owner(Name = @rolename).Lock(Exclusive = 0)

	-- ROLE NAME (OBTAIN OWNER FOR PERMISSIONS) 
	IF @@ERROR = 0
		select @roluid = principal_id, @owner = owning_principal_id from sys.database_principals
			    where name = @rolename and type = 'R'

    -- ERROR IF ROLE NOT FOUND OR PUBLIC 
    if @roluid is null
    begin
		ROLLBACK TRANSACTION
	    raiserror(15409,-1,-1,@rolename)
	    return (1)
    end

    -- CHECK PERMISSIONS 
	-- Only member of db_owner can drop members from db-fixed roles 
	if (not is_member('db_owner') = 1) and
       (not ( (@roluid >=16384 and @roluid <  16400) and is_member('db_owner') = 1))         and
       (not ( (@roluid < 16384 or  @roluid >= 16400) and is_member('db_securityadmin') = 1)) and
       (not ( (@roluid < 16384 or  @roluid >= 16400) and
			((is_member(user_name(@owner)) = 1) or (has_perms_by_name(@rolename, 'role', 'alter') = 1))
			))
    begin
		ROLLBACK TRANSACTION
		EXEC %%System().AuditEvent(ID = 1296321618, Success = 0, TargetLoginName = NULL, TargetUserName = @membername, Role = @rolename, Object = NULL, Provider = NULL, Server = NULL)
		raiserror(15247,-1,-1)
		return (1)
	end
	else
	begin
		EXEC %%System().AuditEvent(ID = 1296321618, Success = 1, TargetLoginName = NULL, TargetUserName = @membername, Role = @rolename, Object = NULL, Provider = NULL, Server = NULL)
	end

	-- EXCL LOCK MEMBER 
	EXEC %%Owner(Name = @membername).Lock(Exclusive = 1) -- may fail, back out below

    -- ERROR IF MEMBER NAME NOT NULL AND NOT FOUND 
	if @@error = 0
		select @memuid = principal_id from sys.database_principals where name = @membername
    if @memuid is null
    begin
		ROLLBACK TRANSACTION
		raiserror(15410, -1, -1, @membername)
		return (1)
    end

    -- CANNOT CHANGE MEMBERSHIP OF FIXED ROLES OR DBO 
    if @membername in ('dbo','public') or (@memuid >= 16384 and @memuid < 16400)
    begin
		ROLLBACK TRANSACTION
        raiserror(15405, -1 ,-1, @membername)
        return (1)
    end

    -- REVOME ROLE MEMBER FOR THIS USER 
    -- INVALIDATE CACHED PERMISSIONS (MEMBERSHIP CHANGES PERMISSIONS) 
	EXEC %%Owner(Name = @membername).SetRoleMember(RoleID = @roluid, IsMember = 0)

	COMMIT TRANSACTION

    -- RETURN SUCCESS 
    return (0) -- sp_droprolemember

 
Last revision 2008RTM
See also

  sp_cdc_drop_objects (Procedure)
sp_changegroup (Procedure)
sp_MSdropmergepalrole (Procedure)
sp_MSdroptranpalrole (Procedure)
sp_MSremovedbreplication (Procedure)
sp_MSrepl_dbrole (Procedure)
sp_MSrepl_drop_all_role_members (Procedure)
sp_revoke_publication_access (Procedure)
       



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