Jen Kuntz offers up a script to clear out unused companies.
Clear Companies script & custom tables
Development & IntegrationSQL & Data
Archived post from 2018. Dynamics GP and the links it points to have changed since; check current documentation before relying on version-specific steps.