Home / Learn Secure SQL / Table and Column Names Cannot Be Bound
Table and Column Names Cannot Be Bound
The one case where prepared statement placeholders do not help.
How to think about this
Definition
Prepared statement placeholders exist only for values (data), never for SQL identifiers like table names, column names, or the direction in ORDER BY. If a feature needs to choose a column or table name dynamically, binding cannot be used for that part at all.
Why you need this
This is the case developers most often get wrong, sometimes building that one small part of the query by string-joining "just this once", which reopens the exact problem the rest of the query avoided.
How it works
Validate the identifier against a fixed allowlist of names your code already knows about, and only ever insert an allowlisted, known-safe name into the query text; never a value taken directly from the user.
Where you'll see this
- Web application code review
- Backend development
- Database administration
Try it
In your own code: if requested_column not in ("name", "price"): reject the request. Only then is it safe to place that exact, now-known-good name into the ORDER BY text.
Test what you just read
1. A dynamic table or column name should be checked against...
Allowlist, not binding, for identifiers.