Worst Practice - Spaces in Object Names

,

I've written a few articles now about various Worst Practices - things that

make your life harder for no good reason! This week is a fairly simple one -

which means it should be easy to prevent. Spaces in object names. SQL supports

them of course, you just put the object name in brackets, like so:

select * from [stupid table name]

Does it really matter? It works after all and isn't that the main thing? Yes,

I'll grant that the fact that it works is worth something. But I do think it

matters. I spend a lot of time in Query Analyzer and it's hard enough to get the

column names right (the Object Browser is a nice help) without having to either

A, put brackets around every object name, or B, remember which objects have

spaces and just put brackets around them. Putting brackets around everything

just adds visual noise. More to my point, why would you need spaces in

object names?

In an effort to avoid problem with spaces, Query Analyzer defaults to putting

brackets around everything, as this script shows:

SELECT [CategoryID], [CategoryName], [Description], [Picture] FROM [Northwind].[dbo].[Categories]

You can turn the bracket generation off (today's QA tip) by clicking Tools,

Options, then selecting None under identifier delimiter:

What about third party applications that create objects with spaces in the

names? I vote for complaining to start with - maybe if they hear it enough

they'll change! In practice I'd say you pretty much have to live with it, not

worth the effort to change. What you can do to make your own life easier is to

create views that alias columns so that they don't have spaces. Again, I'm not

sure it's worth the effort - depends on how much you access them and how much it

aggravates you.

Listen, I know this is a small thing and fairly trivial. The problem with our

line of work is a lot stuff is trivial until you start to combine them. Compare

a database that has no worst practices implemented with one that perhaps has

every worst practice implemented. They both work, but one is soooo much easier

to work with. The nice part about trivial things is they ARE easy to change. Put

out the word - you're just saying no to spaces!

Rate

Share

Share

Rate