The basic method to escape reserved words for SQL Server is the use of the square brackets ([
and ]
). For example, Description and Name are reserved words; however, if there is an object using both as names, the syntax used is:
SELECT [Description]
FROM dbo.TableName
WHERE [Name] = 'foo'
The only special character for SQL Server is the single quote '
and it is escaped by doubling its usage. For example, to find the name O'Shea in the same table, the following syntax would be used:
SELECT [Description]
FROM dbo.TableName
WHERE [Name] = 'O''Shea'