Using SQL Server Reserved Words
Hello again… I hope you had a good holiday weekend for those of you who had the holiday off. Last night I came across a stored procedure that used SQL Server reserved words in the SELECT and INSERT statements. Since I am using SQL Server 2005, the words that came up as “reserved” were:
status
views
subject
user_id
If you must use SQL Server reserved words put brackets [] around them. Putting reserved words in brackets [] is a “tuning” technique that DBAs use to “optimize” T-SQL code. If you do NOT put brackets [] around the reserved words then SQL Server will need to take the time to “resolve” the word and decide if it is being used as a reserved word or if it corresponds to a column in a user table or a literal in a result set. This will take SQL Server longer to execute the T-SQL script. If the reserved words do in fact have brackets [] then SQL Server knows that it corresponds to a column name or as a literal if you use it as a column heading in a result set and will not have to do a compare.
I hope this helps you out… if you have any other way to tune or optimize please comment!
Tags: brackets, insert, optimize, reserved words, select, SQL Server 2005, T-SQL, tune
