Home / Learn Secure SQL / Dynamic Table and Column Names in Practice
Dynamic Table and Column Names in Practice
Multi-tenant tables, pivoted reports, and admin "pick a column" features.
What's actually going on
What it is
Some real features genuinely need to choose a table or column at runtime: a report where the user picks which column to show, or a system with one table per tenant.
Why it matters
These are exactly the features most likely to tempt a developer into string-joining a name directly from user input, because there seems to be no other way.
Mechanically speaking
Map the requested name to a known-safe value through a lookup (a dictionary/hash map in your code, or a database table of permitted names), and only ever use the looked-up, trusted value in the query, never the raw request.
Shows up in
- Web application code review
- Backend development
- Database administration
Try it
The GROUP BY column came from a lookup table in the application code, not directly from the request.
Check yourself
1. For "pick a column to group by" features, the safe approach is...
Lookup/allowlist, not binding.