INSERT INTO VCLib.T_BASE_FEATURE_SETTINGS
           (BaseFeatureSettingsID
           ,ClientModuleFeature
           ,RoleClientModules
           ,type_)
SELECT
           NEWID()--<BaseFeatureSettingsID, uniqueidentifier,>
          ,(select top 1 f.ClientModuleFeatureID from VCLib.T_CLIENT_MODULE_FEATURE f where f."name" = 'CopyAllSelectedObjects')--<ClientModuleFeature, uniqueidentifier,>
          ,rcm.RoleClientModuleID--<RoleClientModules, uniqueidentifier,>
          ,(select top 1 e.EntityID from VCLib.T_ENTITIES e where e.EntName = 'BASE_FEATURE_SETTINGS' and e."schema" = 'VCLib')--<type_, int,>)
from VCLib.T_ROLE_CLIENT_MODULES rcm
    join VCLib.T_CLIENT_MODULES cm on cm.ClientModuleID = rcm.ClientModuleID
where cm.ModuleType = 'UserClientModule'
        and
    not exists
    (
        select *
        from VCLib.T_BASE_FEATURE_SETTINGS bfs
            join VCLib.T_CLIENT_MODULE_FEATURE cmf on cmf.ClientModuleFeatureID = bfs.ClientModuleFeature
        where bfs.RoleClientModules = rcm.RoleClientModuleID
                and
            cmf."name" = 'CopyAllSelectedObjects'
    )
GO
