There is an example of [dis]allowing certain bash commands here: https://code.claude.com/docs/en/settings
As for queries, you might be able to achieve the same thing with usage of command-line tools if it's a `sqlite` database (I am not sure about other SQL DBs). If you want even more control than the settings.json allows, you can use the claude code SDK.