Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Worst Practice - Spaces in Object Names

By Andy Warren,

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!

Total article views: 7169 | Views in the last 30 days: 0
 
Related Articles
BLOG

Spaces in Object Names Revisited

I think in general the SQL Server DBA’s of the world prefer that object names not have spaces embedd...

FORUM

Use of brackets around data names

We recently upgraded to SQL Server 2012 and the Query Analyzer defaults to putting all data names in...

FORUM

Worst Practice - Spaces in Object Names

Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/column...

ARTICLE

Worst Practices - Objects Not Owned by DBO

Last week Andy launched a new series about Worst Practices by talking about why the Hungarian naming...

 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones