Is it okay to put dots in SQL Server database names?

You can, but I wouldn't. You would always have to wrap the DB name with square brackets such as [MyApp.Sales].

So to recap: if you value your sanity, don't do it.


I think it's a very bad idea even if technically possible.

Over the years I found out that many people have trouble understanding the four-part naming convention even though it seems pretty obvious:

server_name.database_name.schema_name.object_name

Imagine what will happen if they see something like this:

MAIN-SQL.[MyApp.Sales].hr.CompetitorsProducts

or:

[MAIN-SQL\EXPRESS].[MyApp.Sales].sch_HR.[Products From.Our-Competitors]

Keeping things simple is important.


In case someone else encounters this question...

Keep in mind that it is not only a bad idea because users might be confused, but also because some tools might get confused.

Even Microsoft itself has problems with this. If you try to connect your database to an excel sheet using Microsoft Query (via ODBC), you get a configuration wizard which lets you choose the database you want to connect to. However choosing a database that contains a dot will produce an error stating that the server could not be found. It seems that the wizard does not check if the values needs escaping and blindly concatenates the identifiers.

There are of course workarrounds, but you save yourself some trouble by not doing this from the start.

Tags:

Sql Server