Characters you should never ever use in an object or schema name!

Leave a comment

March 5, 2014 by Kenneth Fisher

You can put pretty much any character you want into an object or schema name by enclosing the name in []’s. This does not however mean that you should. There are two specific cases that I’ve seen that are in general a bad idea.

I’ve seen names that actually have []s around them.

CREATE SCHEMA [[bracket]]]
	CREATE TABLE [[bracket]]] (id int)
GO
SELECT * FROM [[backet]]].[[bracket]]]
GO

And other’s that have periods.

CREATE SCHEMA [do.t]
	CREATE TABLE [do.t].[do.t] (id int)
GO
SELECT * FROM [do.t].[do.t]
GO

Why is this a problem? Well you can see from above you have to do extra work to even do a select. Also there are a number of commands that just won’t work. Sp_help for example.

EXEC sp_help [[bracket]].[bracket]]]
GO
EXEC sp_help [do.t.do.t]
GO

And if nothing else they are really really confusing! So please do not put periods or brackets in object or schema names. Do it for me if not for yourself. I mean there is always that outside chance that I’ll have to work on your systems one day!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 2,146 other followers

Follow me on Twitter

ToadWorld Pro of the Month November 2013
%d bloggers like this: