While deciding the direct execution of SQL queries on SharePoint databases, you should consider the following questions and plan accordingly-

What can be the possible repercussions, if we execute direct SQL queries on the content database?

What are unsupported operations on SharePoint Content Databases?

It is clearly unsupported to update, delete or insert the records. The risks are surely far more obvious. Any database changes would definitely break the support, as stated by Microsoft. Examples of such database changes include, but are not limited to the following:

What are the supported operations on SharePoint Databases?

What happens if unsupported data modification is discovered?

If an unsupported database modification is discovered during a support call, the customer must perform one of the following procedures at a minimum:

What if a previous version of the database that does not include the unsupported modifications is unavailable or if the customer cannot roll back the database modifications?

What can be done if the content database still needs to be queried directly for some reason?

Never run the direct SQL queries on the content database in Production environment.

Follow the steps

Before running the steps, mentioned above, make sure the database is not in intermediate stage [nothing is checked out], else the user can get different document count than actual.

Key Takeaways

Based on the facts exposed by Microsoft Documentation on direct query execution on the content databases, the key takeaways are mentioned below.