bitflood
bitflood

Reputation: 441

SQL Server case sensitive database names

In MS SQL Sever, it is possible to have case sensitive database names. So in other words is there a way to create 2 databases on the same instance 'create database db1' and 'create database DB1'?

If yes, how to enable this? (I tried doing it myself, and it did not allow me to create the 2nd time, but I am not sure if I missed any setting)

Note: I have seen existing questions on this on SO but they seem to refer to the objects in the database and I am referring to the database name itself.

(The reason for the question is not to setup the databases this way but to know if such scenario can happen so as that I can include in my testing)

Upvotes: 3

Views: 10623

Answers (2)

HBT
HBT

Reputation: 19

Yes, you can create the databases in the same instance by adjusting the collation property as "CS" of the required database. Reference

MSQL Server is, by default, case insensitive; however, it is possible to create a case-sensitive SQL Server database and even to make specific table columns case sensitive. The way to determine if a database or database object is to check its "COLLATION" property and look for "CI" or "CS" in the result.

CI = Case Insensitive CS = Case Sensitive

Upvotes: 1

Bacon Bits
Bacon Bits

Reputation: 32145

You may be able to accomplish this by setting the server collation at install to case-sensitive, or changing it by recreating the master database using a case-sensitive collation. Since the master database is the database of user-level metadata, it stands to reason that if anything would enforce case-sensitive server object names, the master database would.

I don't know how rigid it is offhand, however. I have a 2k8R2 server with server collation set to Latin1_General_CS_AS, and I have to spell database names correctly in use statements or when calling from linked servers. However, none of the databases attached to that server have case-insensitive collation. It may be that if your current DB is case-insensitive that you can use case insensitive names. I don't know.

I've also never tried creating a DB on that server with the same name as an existing DB except with different case. I don't know if it would allow it.

Upvotes: 3

Related Questions