How do I delete a Support Group?

Version 1
    Question

    The attached will hard delete a soft deleted support group, so long as there are no references to any of those groups. Please take a backup first, because if it fails it will typically be on the very last line.

    Answer

    -- flag the groups to be deleted     

    update tps_group set tps_deleted=9

         where tps_deleted=1 and tps_group_type_guid = (select tps_guid from tps_group_type where tps_name='Support Group')

     

    -- delete links to these grooups

    delete from tps_user_group where tps_group_id in

         (SELECT tps_guid FROM tps_group WHERE tps_deleted=9)

    delete from km_group_knowledge_domain_cat where km_group_guid in     

         (SELECT tps_guid FROM tps_group WHERE tps_deleted=9)

     

    update tps_user set tps_current_group_guid = null where tps_current_group_guid in

         (SELECT tps_guid FROM tps_group WHERE tps_deleted=9)

    update tps_user set tps_primary_group_guid = null where tps_primary_group_guid in

         (SELECT tps_guid FROM tps_group WHERE tps_deleted=9)

                             

    -- delete the groups

    DELETE FROM tps_support_group where tps_guid in     

         (SELECT tps_guid FROM tps_group WHERE tps_deleted=9)

    DELETE FROM tps_group WHERE tps_deleted=9

    Environment

    ITBM all versions