Blog Post

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

,

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!

Filed under: Microsoft SQL Server, SQLServerPedia Syndication, T-SQL Tagged: code language, language sql, microsoft sql server, sql statements, T-SQL

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating