delete from tbl_ORG_AttributeLinks where mstr_attrTypeId = and mstr_attrId in () and child_attrTypeId = and child_attrId = insert into tbl_ORG_AttributeLinks (mstr_attrTypeId, mstr_attrId, child_attrTypeId, child_attrId) select , , , where not exists (select 1 from tbl_ORG_AttributeLinks with (nolock) where mstr_attrTypeId = and mstr_attrId = and child_attrTypeId = and child_attrId = )