Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if string is SQL Server Reserved Keywords or not

Is it possible to determine if any string is a SQL Server Reserved keywords or not?

Logic should like -

IF @string is SQL Server Reserved Keywords
     RETURN 1
ELSE 
     RETURN 0
like image 863
AgentSQL Avatar asked Jan 13 '23 15:01

AgentSQL


2 Answers

As far as I know there is no built-in way. You can write your own function that would compare the string against known reserved words from documentation.

This list can be kept dynamic in a table so as it changes (e.g. for different versions of SQL Server) the table can be updated.

Also this way a single SELECT statement will yield the result.

like image 148
Yuriy Galanter Avatar answered Jan 16 '23 01:01

Yuriy Galanter


You could make a table containing keywords. A list can be found here: http://msdn.microsoft.com/en-us/library/ms189822.aspx

Then you can use a join with where to determine if a string is reserved.

like image 27
Menelaos Avatar answered Jan 16 '23 00:01

Menelaos