Column names and table names should not use reserved keywords in your database. You can use reserved keywords because SQL Server will allow it. However, this should not be done because it makes writing and reading queries more difficult. When you use a reserved keyword for a column or table name, you need to use [square brackets] around the name.
The following query compares your column names against a list of identified keywords. Some of the keywords are SQL Server reserved words, some are ODBC reserved words, and the rest are future reserved words.
How to detect this problem:
Declare @Temp Table(Data VarChar(50))
Insert Into @Temp Values('ABSOLUTE')
Insert Into @Temp Values('ACTION')
Insert Into @Temp Values('ADA')
Insert Into @Temp Values('ADD')
Insert Into @Temp Values('ADMIN')
Insert Into @Temp Values('AFTER')
Insert Into @Temp Values('AGGREGATE')
Insert Into @Temp Values('ALIAS')
Insert Into @Temp Values('ALL')
Insert Into @Temp Values('ALLOCATE')
Insert Into @Temp Values('ALTER')
Insert Into @Temp Values('AND')
Insert Into @Temp Values('ANY')
Insert Into @Temp Values('ARE')
Insert Into @Temp Values('ARRAY')
Insert Into @Temp Values('AS')
Insert Into @Temp Values('ASC')
Insert Into @Temp Values('ASSERTION')
Insert Into @Temp Values('AT')
Insert Into @Temp Values('AUTHORIZATION')
Insert Into @Temp Values('AVG')
Insert Into @Temp Values('BACKUP')
Insert Into @Temp Values('BEFORE')
Insert Into @Temp Values('BEGIN')
Insert Into @Temp Values('BETWEEN')
Insert Into @Temp Values('BINARY')
Insert Into @Temp Values('BIT')
Insert Into @Temp Values('BIT_LENGTH')
Insert Into @Temp Values('BLOB')
Insert Into @Temp Values('BOOLEAN')
Insert Into @Temp Values('BOTH')
Insert Into @Temp Values('BREADTH')
Insert Into @Temp Values('BREAK')
Insert Into @Temp Values('BROWSE')
Insert Into @Temp Values('BULK')
Insert Into @Temp Values('BY')
Insert Into @Temp Values('CALL')
Insert Into @Temp Values('CASCADE')
Insert Into @Temp Values('CASCADED')
Insert Into @Temp Values('CASE')
Insert Into @Temp Values('CAST')
Insert Into @Temp Values('CATALOG')
Insert Into @Temp Values('CHAR')
Insert Into @Temp Values('CHAR_LENGTH')
Insert Into @Temp Values('CHARACTER')
Insert Into @Temp Values('CHARACTER_LENGTH')
Insert Into @Temp Values('CHECK')
Insert Into @Temp Values('CHECKPOINT')
Insert Into @Temp Values('CLASS')
Insert Into @Temp Values('CLOB')
Insert Into @Temp Values('CLOSE')
Insert Into @Temp Values('CLUSTERED')
Insert Into @Temp Values('COALESCE')
Insert Into @Temp Values('COLLATE')
Insert Into @Temp Values('COLLATION')
Insert Into @Temp Values('COLUMN')
Insert Into @Temp Values('COMMIT')
Insert Into @Temp Values('COMPLETION')
Insert Into @Temp Values('COMPUTE')
Insert Into @Temp Values('CONNECT')
Insert Into @Temp Values('CONNECTION')
Insert Into @Temp Values('CONSTRAINT')
Insert Into @Temp Values('CONSTRAINTS')
Insert Into @Temp Values('CONSTRUCTOR')
Insert Into @Temp Values('CONTAINS')
Insert Into @Temp Values('CONTAINSTABLE')
Insert Into @Temp Values('CONTINUE')
Insert Into @Temp Values('CONVERT')
Insert Into @Temp Values('CORRESPONDING')
Insert Into @Temp Values('COUNT')
Insert Into @Temp Values('CREATE')
Insert Into @Temp Values('CROSS')
Insert Into @Temp Values('CUBE')
Insert Into @Temp Values('CURRENT')
Insert Into @Temp Values('CURRENT_DATE')
Insert Into @Temp Values('CURRENT_PATH')
Insert Into @Temp Values('CURRENT_ROLE')
Insert Into @Temp Values('CURRENT_TIME')
Insert Into @Temp Values('CURRENT_TIMESTAMP')
Insert Into @Temp Values('CURRENT_USER')
Insert Into @Temp Values('CURSOR')
Insert Into @Temp Values('CYCLE')
Insert Into @Temp Values('DATA')
Insert Into @Temp Values('DATABASE')
Insert Into @Temp Values('DATE')
Insert Into @Temp Values('DAY')
Insert Into @Temp Values('DBCC')
Insert Into @Temp Values('DEALLOCATE')
Insert Into @Temp Values('DEC')
Insert Into @Temp Values('DECIMAL')
Insert Into @Temp Values('DECLARE')
Insert Into @Temp Values('DEFAULT')
Insert Into @Temp Values('DEFERRABLE')
Insert Into @Temp Values('DEFERRED')
Insert Into @Temp Values('DELETE')
Insert Into @Temp Values('DENY')
Insert Into @Temp Values('DEPTH')
Insert Into @Temp Values('DEREF')
Insert Into @Temp Values('DESC')
Insert Into @Temp Values('DESCRIBE')
Insert Into @Temp Values('DESCRIPTOR')
Insert Into @Temp Values('DESTROY')
Insert Into @Temp Values('DESTRUCTOR')
Insert Into @Temp Values('DETERMINISTIC')
Insert Into @Temp Values('DIAGNOSTICS')
Insert Into @Temp Values('DICTIONARY')
Insert Into @Temp Values('DISCONNECT')
Insert Into @Temp Values('DISK')
Insert Into @Temp Values('DISTINCT')
Insert Into @Temp Values('DISTRIBUTED')
Insert Into @Temp Values('DOMAIN')
Insert Into @Temp Values('DOUBLE')
Insert Into @Temp Values('DROP')
Insert Into @Temp Values('DUMMY')
Insert Into @Temp Values('DUMP')
Insert Into @Temp Values('DYNAMIC')
Insert Into @Temp Values('EACH')
Insert Into @Temp Values('ELSE')
Insert Into @Temp Values('END')
Insert Into @Temp Values('END-EXEC')
Insert Into @Temp Values('EQUALS')
Insert Into @Temp Values('ERRLVL')
Insert Into @Temp Values('ESCAPE')
Insert Into @Temp Values('EVERY')
Insert Into @Temp Values('EXCEPT')
Insert Into @Temp Values('EXCEPTION')
Insert Into @Temp Values('EXEC')
Insert Into @Temp Values('EXECUTE')
Insert Into @Temp Values('EXISTS')
Insert Into @Temp Values('EXIT')
Insert Into @Temp Values('EXTERNAL')
Insert Into @Temp Values('EXTRACT')
Insert Into @Temp Values('FALSE')
Insert Into @Temp Values('FETCH')
Insert Into @Temp Values('FILE')
Insert Into @Temp Values('FILLFACTOR')
Insert Into @Temp Values('FIRST')
Insert Into @Temp Values('FLOAT')
Insert Into @Temp Values('FOR')
Insert Into @Temp Values('FOREIGN')
Insert Into @Temp Values('FORTRAN')
Insert Into @Temp Values('FOUND')
Insert Into @Temp Values('FREE')
Insert Into @Temp Values('FREETEXT')
Insert Into @Temp Values('FREETEXTTABLE')
Insert Into @Temp Values('FROM')
Insert Into @Temp Values('FULL')
Insert Into @Temp Values('FUNCTION')
Insert Into @Temp Values('GENERAL')
Insert Into @Temp Values('GET')
Insert Into @Temp Values('GLOBAL')
Insert Into @Temp Values('GO')
Insert Into @Temp Values('GOTO')
Insert Into @Temp Values('GRANT')
Insert Into @Temp Values('GROUP')
Insert Into @Temp Values('GROUPING')
Insert Into @Temp Values('HAVING')
Insert Into @Temp Values('HOLDLOCK')
Insert Into @Temp Values('HOST')
Insert Into @Temp Values('HOUR')
Insert Into @Temp Values('IDENTITY')
Insert Into @Temp Values('IDENTITY_INSERT')
Insert Into @Temp Values('IDENTITYCOL')
Insert Into @Temp Values('IF')
Insert Into @Temp Values('IGNORE')
Insert Into @Temp Values('IMMEDIATE')
Insert Into @Temp Values('IN')
Insert Into @Temp Values('INCLUDE')
Insert Into @Temp Values('INDEX')
Insert Into @Temp Values('INDICATOR')
Insert Into @Temp Values('INITIALIZE')
Insert Into @Temp Values('INITIALLY')
Insert Into @Temp Values('INNER')
Insert Into @Temp Values('INOUT')
Insert Into @Temp Values('INPUT')
Insert Into @Temp Values('INSENSITIVE')
Insert Into @Temp Values('INSERT')
Insert Into @Temp Values('INT')
Insert Into @Temp Values('INTEGER')
Insert Into @Temp Values('INTERSECT')
Insert Into @Temp Values('INTERVAL')
Insert Into @Temp Values('INTO')
Insert Into @Temp Values('IS')
Insert Into @Temp Values('ISOLATION')
Insert Into @Temp Values('ITERATE')
Insert Into @Temp Values('JOIN')
Insert Into @Temp Values('KEY')
Insert Into @Temp Values('KILL')
Insert Into @Temp Values('LANGUAGE')
Insert Into @Temp Values('LARGE')
Insert Into @Temp Values('LAST')
Insert Into @Temp Values('LATERAL')
Insert Into @Temp Values('LEADING')
Insert Into @Temp Values('LEFT')
Insert Into @Temp Values('LESS')
Insert Into @Temp Values('LEVEL')
Insert Into @Temp Values('LIKE')
Insert Into @Temp Values('LIMIT')
Insert Into @Temp Values('LINENO')
Insert Into @Temp Values('LOAD')
Insert Into @Temp Values('LOCAL')
Insert Into @Temp Values('LOCALTIME')
Insert Into @Temp Values('LOCALTIMESTAMP')
Insert Into @Temp Values('LOCATOR')
Insert Into @Temp Values('LOWER')
Insert Into @Temp Values('MAP')
Insert Into @Temp Values('MATCH')
Insert Into @Temp Values('MAX')
Insert Into @Temp Values('MIN')
Insert Into @Temp Values('MINUTE')
Insert Into @Temp Values('MODIFIES')
Insert Into @Temp Values('MODIFY')
Insert Into @Temp Values('MODULE')
Insert Into @Temp Values('MONTH')
Insert Into @Temp Values('NAMES')
Insert Into @Temp Values('NATIONAL')
Insert Into @Temp Values('NATURAL')
Insert Into @Temp Values('NCHAR')
Insert Into @Temp Values('NCLOB')
Insert Into @Temp Values('NEW')
Insert Into @Temp Values('NEXT')
Insert Into @Temp Values('NO')
Insert Into @Temp Values('NOCHECK')
Insert Into @Temp Values('NONCLUSTERED')
Insert Into @Temp Values('NONE')
Insert Into @Temp Values('NOT')
Insert Into @Temp Values('NULL')
Insert Into @Temp Values('NULLIF')
Insert Into @Temp Values('NUMERIC')
Insert Into @Temp Values('OBJECT')
Insert Into @Temp Values('OCTET_LENGTH')
Insert Into @Temp Values('OF')
Insert Into @Temp Values('OFF')
Insert Into @Temp Values('OFFSETS')
Insert Into @Temp Values('OLD')
Insert Into @Temp Values('ON')
Insert Into @Temp Values('ONLY')
Insert Into @Temp Values('OPEN')
Insert Into @Temp Values('OPENDATASOURCE')
Insert Into @Temp Values('OPENQUERY')
Insert Into @Temp Values('OPENROWSET')
Insert Into @Temp Values('OPENXML')
Insert Into @Temp Values('OPERATION')
Insert Into @Temp Values('OPTION')
Insert Into @Temp Values('OR')
Insert Into @Temp Values('ORDER')
Insert Into @Temp Values('ORDINALITY')
Insert Into @Temp Values('OUT')
Insert Into @Temp Values('OUTER')
Insert Into @Temp Values('OUTPUT')
Insert Into @Temp Values('OVER')
Insert Into @Temp Values('OVERLAPS')
Insert Into @Temp Values('PAD')
Insert Into @Temp Values('PARAMETER')
Insert Into @Temp Values('PARAMETERS')
Insert Into @Temp Values('PARTIAL')
Insert Into @Temp Values('PASCAL')
Insert Into @Temp Values('PATH')
Insert Into @Temp Values('PERCENT')
Insert Into @Temp Values('PLAN')
Insert Into @Temp Values('POSITION')
Insert Into @Temp Values('POSTFIX')
Insert Into @Temp Values('PRECISION')
Insert Into @Temp Values('PREFIX')
Insert Into @Temp Values('PREORDER')
Insert Into @Temp Values('PREPARE')
Insert Into @Temp Values('PRESERVE')
Insert Into @Temp Values('PRIMARY')
Insert Into @Temp Values('PRINT')
Insert Into @Temp Values('PRIOR')
Insert Into @Temp Values('PRIVILEGES')
Insert Into @Temp Values('PROC')
Insert Into @Temp Values('PROCEDURE')
Insert Into @Temp Values('PUBLIC')
Insert Into @Temp Values('RAISERROR')
Insert Into @Temp Values('READ')
Insert Into @Temp Values('READS')
Insert Into @Temp Values('READTEXT')
Insert Into @Temp Values('REAL')
Insert Into @Temp Values('RECONFIGURE')
Insert Into @Temp Values('RECURSIVE')
Insert Into @Temp Values('REF')
Insert Into @Temp Values('REFERENCES')
Insert Into @Temp Values('REFERENCING')
Insert Into @Temp Values('RELATIVE')
Insert Into @Temp Values('REPLICATION')
Insert Into @Temp Values('RESTORE')
Insert Into @Temp Values('RESTRICT')
Insert Into @Temp Values('RESULT')
Insert Into @Temp Values('RETURN')
Insert Into @Temp Values('RETURNS')
Insert Into @Temp Values('REVOKE')
Insert Into @Temp Values('RIGHT')
Insert Into @Temp Values('ROLE')
Insert Into @Temp Values('ROLLBACK')
Insert Into @Temp Values('ROLLUP')
Insert Into @Temp Values('ROUTINE')
Insert Into @Temp Values('ROW')
Insert Into @Temp Values('ROWCOUNT')
Insert Into @Temp Values('ROWGUIDCOL')
Insert Into @Temp Values('ROWS')
Insert Into @Temp Values('RULE')
Insert Into @Temp Values('SAVE')
Insert Into @Temp Values('SAVEPOINT')
Insert Into @Temp Values('SCHEMA')
Insert Into @Temp Values('SCOPE')
Insert Into @Temp Values('SCROLL')
Insert Into @Temp Values('SEARCH')
Insert Into @Temp Values('SECOND')
Insert Into @Temp Values('SECTION')
Insert Into @Temp Values('SELECT')
Insert Into @Temp Values('SEQUENCE')
Insert Into @Temp Values('SESSION')
Insert Into @Temp Values('SESSION_USER')
Insert Into @Temp Values('SET')
Insert Into @Temp Values('SETS')
Insert Into @Temp Values('SETUSER')
Insert Into @Temp Values('SHUTDOWN')
Insert Into @Temp Values('SIZE')
Insert Into @Temp Values('SMALLINT')
Insert Into @Temp Values('SOME')
Insert Into @Temp Values('SPACE')
Insert Into @Temp Values('SPECIFIC')
Insert Into @Temp Values('SPECIFICTYPE')
Insert Into @Temp Values('SQL')
Insert Into @Temp Values('SQLCA')
Insert Into @Temp Values('SQLCODE')
Insert Into @Temp Values('SQLERROR')
Insert Into @Temp Values('SQLEXCEPTION')
Insert Into @Temp Values('SQLSTATE')
Insert Into @Temp Values('SQLWARNING')
Insert Into @Temp Values('START')
Insert Into @Temp Values('STATE')
Insert Into @Temp Values('STATEMENT')
Insert Into @Temp Values('STATIC')
Insert Into @Temp Values('STATISTICS')
Insert Into @Temp Values('STRUCTURE')
Insert Into @Temp Values('SUBSTRING')
Insert Into @Temp Values('SUM')
Insert Into @Temp Values('SYSTEM_USER')
Insert Into @Temp Values('TABLE')
Insert Into @Temp Values('TEMPORARY')
Insert Into @Temp Values('TERMINATE')
Insert Into @Temp Values('TEXTSIZE')
Insert Into @Temp Values('THAN')
Insert Into @Temp Values('THEN')
Insert Into @Temp Values('TIME')
Insert Into @Temp Values('TIMESTAMP')
Insert Into @Temp Values('TIMEZONE_HOUR')
Insert Into @Temp Values('TIMEZONE_MINUTE')
Insert Into @Temp Values('TO')
Insert Into @Temp Values('TOP')
Insert Into @Temp Values('TRAILING')
Insert Into @Temp Values('TRAN')
Insert Into @Temp Values('TRANSACTION')
Insert Into @Temp Values('TRANSLATE')
Insert Into @Temp Values('TRANSLATION')
Insert Into @Temp Values('TREAT')
Insert Into @Temp Values('TRIGGER')
Insert Into @Temp Values('TRIM')
Insert Into @Temp Values('TRUE')
Insert Into @Temp Values('TRUNCATE')
Insert Into @Temp Values('TSEQUAL')
Insert Into @Temp Values('UNDER')
Insert Into @Temp Values('UNION')
Insert Into @Temp Values('UNIQUE')
Insert Into @Temp Values('UNKNOWN')
Insert Into @Temp Values('UNNEST')
Insert Into @Temp Values('UPDATE')
Insert Into @Temp Values('UPDATETEXT')
Insert Into @Temp Values('UPPER')
Insert Into @Temp Values('USAGE')
Insert Into @Temp Values('USE')
Insert Into @Temp Values('USER')
Insert Into @Temp Values('USING')
Insert Into @Temp Values('VALUE')
Insert Into @Temp Values('VALUES')
Insert Into @Temp Values('VARCHAR')
Insert Into @Temp Values('VARIABLE')
Insert Into @Temp Values('VARYING')
Insert Into @Temp Values('VIEW')
Insert Into @Temp Values('WAITFOR')
Insert Into @Temp Values('WHEN')
Insert Into @Temp Values('WHENEVER')
Insert Into @Temp Values('WHERE')
Insert Into @Temp Values('WHILE')
Insert Into @Temp Values('WITH')
Insert Into @Temp Values('WITHOUT')
Insert Into @Temp Values('WORK')
Insert Into @Temp Values('WRITE')
Insert Into @Temp Values('WRITETEXT')
Insert Into @Temp Values('YEAR')
Insert Into @Temp Values('ZONE')
Select object_name(C.object_id), C.Name
From sys.columns As C
Inner Join sys.objects As O
On C.object_id = O.object_id
Inner Join @Temp T
On C.Name = Data
Where is_ms_shipped = 0
Order By object_name(C.object_id), C.Name
How to correct it:
Correcting for this type of problem can be challenging because you cannot just willy nilly go around changing column names. You are likely to have code that uses the column with the original name and this code will need to change to accommodate the changed column name. To make matters more difficult, you could have systems outside of the database that are sending dynamic SQL making it more difficult to find all of the occurrences in code.