Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use a SQL Server keyword as a column name?

I am designing a database and recently named a column in a table DayOfWeek, completely forgetting that DayOfWeek is a built-in function in SQL Server. Now I am deciding if I should just leave it as is and reference the column with square brackets [DayOfWeek] or change the column name to avoid any conflicts in the future. I am not too far into the project so changing it is not too hard. The debate in my head is that the column name of DayOfWeek just makes so much sense for its purpose, so I really want to use it... but it is a reserved word... and could cause pain in the future (especially if I always have to put square brackets around it when referencing the column).

What does everyone think?

like image 412
Jeff Widmer Avatar asked Jun 19 '09 10:06

Jeff Widmer


2 Answers

I would change it - i've got a legacy table called user - it is a pain with the square brackets all the time. perhaps call it DayOfWeekName or DayOFWeekId

Josh

like image 166
Josh Avatar answered Oct 04 '22 01:10

Josh


Jeff,

If you're not too far down the track to rename the column (relatively) painlessly then I'd recommend you change it. You've identified one probable-future-headache for the maintentance crew, and I guess it would be actually less costly (over time) to clean it up now, especially considering that renaming something isn't the hell-on-wheels since the advent of truly effective search and replace functionality in text-editors and IDE's.

The truly hard part of renaming it is gaining the understanding required to do the job safely. You are unique (being the author) in having that understanding. If you asked me (just for instance) to do the job, then it probably wouldn't be a cost effective business proposition.

So... +1 for fixing the sucker yourself... and +2 for not doing it again ;-)

Cheers. Keith.

like image 37
corlettk Avatar answered Oct 04 '22 00:10

corlettk