What is the full syntax of a string literal in T-SQL?
I could not find any explicit definition of string syntax in the official documentation, and any blog post I could find only mentioned certain aspects (like the N
prefix). Additionally, any posts on Stack Overflow or other sites that asked how to escape a string had answers that pointed to using parameters instead of answering the question, which doesn't provide me the information I'm looking for.
From what I can tell, a string literal starts with an optional N
followed by a wrapper of single quotes (or double quotes, if a setting is set a certain way), single quotes within the string are escaped by doubling the single quote, and backslashes are escaped by doubling the backslash (possibly only if a setting is set a certain way?).
Is there an authoritative and/or comprehensive source for this information? Even just a list of reserved/special characters would be better than what I was able to find.