Using reserved words as identifiers in SQL Server:\nEvaluate the statement:\n\n"An SQL Server reserved word must be placed in brackets; otherwise SQL Server treats it as a keyword rather than an identifier."

Difficulty: Easy

Correct Answer: Correct

Explanation:


Introduction / Context:
SQL Server has a list of reserved keywords (e.g., SELECT, FROM, TABLE). If you want to use such a word as the name of a table, column, or other object, you must delimit it so the parser treats it as an identifier and not as part of SQL syntax.


Given Data / Assumptions:

  • Default T-SQL settings; QUOTED_IDENTIFIER may be ON or OFF.
  • Example identifiers like [Table], [Key], [User].
  • We focus on standards-compliant and robust practices.


Concept / Approach:
SQL Server supports two delimiter styles for identifiers: square brackets [name] and double quotes "name" (with QUOTED_IDENTIFIER ON). Using brackets is the most common T-SQL approach. Without delimiters, a reserved word cannot be parsed as an identifier and will cause errors or ambiguous parsing. While best practice is to avoid reserved words entirely, bracketed or quoted identifiers are the supported escape mechanism.


Step-by-Step Solution:

Try CREATE TABLE select (id int); → parse error.Use CREATE TABLE [select] (id int); → succeeds (not recommended naming).Alternatively, with QUOTED_IDENTIFIER ON: CREATE TABLE "select" (id int);Conclusion: Reserved words must be delimited to be used as identifiers.


Verification / Alternative check:
Test statements in SSMS; review the list of reserved keywords in Microsoft documentation and note parsing failures without delimiters.


Why Other Options Are Wrong:

  • Incorrect: Contradicts parser behavior.
  • Collation / QUOTED_IDENTIFIER caveats: Case or quoted-identifier settings do not make undelimited reserved words valid identifiers.
  • System views only: The rule applies universally.


Common Pitfalls:
Building ORMs or code generators that emit un-delimited reserved names; changing QUOTED_IDENTIFIER unexpectedly.


Final Answer:
Correct

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion