It seems that you cannot handled cases with roles, being owned by a user.
Create 2 empty database, Test1 and Test2
execute the script below on Test1. Do a Sql Comparsion between Test1 and Test2. select both the user and role, and synchronize Test2 into Test1, meaning the user and role should be dropped. However it will fail with "The database principal owns a database role and cannot be dropped".
Apparently this do work, if the role is owned by dbo
Run this script on:
DEVDB22-S1.SYS.DOM\\DEV01.Dummy2 - This database will be modified
to synchronize it with:
You are recommended to back up your database before running this script
Script created by SQL Compare version 10.7.0 from Red Gate Software Ltd at 13-05-2014 16:15:37
SET NUMERIC_ROUNDABORT OFF
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, QUOTED_IDENTIFIER, ANSI_NULLS ON
IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE id=OBJECT_ID('tempdb..#tmpErrors')) DROP TABLE #tmpErrors
CREATE TABLE #tmpErrors (Error int)
SET XACT_ABORT ON
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
CREATE USER [TestUser] WITHOUT LOGIN
PRINT N'Creating role TestRole'
CREATE ROLE [TestRole]
IF EXISTS (SELECT * FROM #tmpErrors) ROLLBACK TRANSACTION
IF @@TRANCOUNT>0 BEGIN
PRINT 'The database update succeeded'
ELSE PRINT 'The database update failed'
DROP TABLE #tmpErrors