Writing adhoc queries to a database is non-compliant. It is always better to formalize the queries into programmatic transformation code. Aside from that, queries should be versioned and trackable so a change data capture could be reported into a downstream system for transparency as a continuation of data lineage. Non-compliant queries not only break governance standards, but in a highly regulated sector could result in fines for an organization.