SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

Worst Practice - Spaces in Object Names

By Andy Warren, 2003/10/01

Total article views: 6666 | Views in the last 30 days: 19

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!

By Andy Warren, 2003/10/01

Total article views: 6666 | Views in the last 30 days: 19
Your response
 
 
Related tags
 
Already registered?  

Free registration required

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com