To get the system database name (used to be known as the DYNAMICS database) from any GP company, use the following SQL:
SELECT TOP 1 DBNAME FROM SY00100 (NOLOCK)
When issued in the context of a company database, this will tell you the name of the system database that manages it. Typically this statement will return
Note: In a multi-tennant environment this may not be the standard DYNAMICS.