Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSdroptranpalrole

  No additional text.


Syntax
create procedure sys.sp_MSdroptranpalrole
(
    @pubid int = NULL
)
AS
begin
    declare @retcode int
                ,@role sysname
                ,@member sysname

    if (@pubid is NULL)
    begin
        if (object_id('dbo.syspublications') is null)
        begin
            return 0
        end
        else
        begin
            declare #hc1 cursor local fast_forward for
                select pubid from dbo.syspublications
            for read only
        	
            open #hc1
            fetch #hc1 into @pubid
            while @@fetch_status <> -1
            BEGIN
                exec @retcode = sys.sp_MSdroptranpalrole @pubid
                if @retcode<>0 or @@error<>0
                    return 1
                fetch #hc1 into @pubid
            END
            close #hc1
            deallocate #hc1
        end
    end
    
    -- drop the database role that contains users who have access to the publication
    -- this has to be done outside the transaction since role operations cannot be
    -- done in transaction
    -- Use the dbid space as wild character as dbid can be different if we are cleaning
    -- up a restored db.
    
    select @role = name from sys.database_principals
        where name like N'MSReplPAL_%_' + cast(@pubid as nvarchar(10)) and type = 'R'
    if (@role is not null)
    begin
        
        -- check if this role is a memeber of the database pal role. Drop it from there.
        
        if exists (select * from sys.database_principals where name='MStran_PAL_role' and type = 'R')
        begin
            exec @retcode = dbo.sp_droprolemember 'MStran_PAL_role', @role
            if (@retcode <> 0 or @@error <> 0)
                return 1
        end
        
        -- drop the members of this role
        
        declare #role_members cursor local fast_forward for
            select u.name
            from sys.database_principals u, sys.database_principals g, sys.database_role_members m
            where g.name = @role
                and g.principal_id = m.role_principal_id
                and g.type = 'R'
                and u.principal_id = m.member_principal_id
        for read only
    				
        open #role_members
        fetch #role_members into @member
        while @@fetch_status <> -1
        begin
            exec @retcode = sys.sp_droprolemember @role, @member
            if (@retcode <> 0 or @@error <> 0)
            BEGIN
                raiserror (14005, 16, -1)
                return (1)
            END
            fetch #role_members into @member
        end
        close #role_members
        deallocate #role_members
        
        -- drop the role
        
        exec @retcode = sys.sp_droprole @role
        if (@retcode <> 0 or @@error <> 0)
        BEGIN
            raiserror (14005, 16, -1)
            return (1)
        END
    end
    
    -- all done
    
    return 0
end

 
Last revision 2008RTM
See also

  sp_MSdrop_repltran (Procedure)
sp_MSrepl_droppublication (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