0

What is the encoding of the database name if I create a db by the query "CREATE DATABASE xxx" in sql server 2012? I found it's not allowed to explicitly define the db name as a unicode string as N'xxx' in this statement.

3
  • 1
    strings are not names. In places where SQL Server expects a name, giving it a string won't work. (Of course, in places it expects a string, if you give it a name and that resolves to e.g. a column whose contents is a string, that can, often, work). There aren't many places where SQL Server gives you the option of providing either of a name or a string. Commented Jan 15, 2014 at 13:36
  • What do you want to accomplish? Create a database with a dynamic name? Commented Jan 15, 2014 at 13:51
  • possible duplicate of Create a database with dynamic database name in sql server 2005 Commented Jan 15, 2014 at 13:51

1 Answer 1

0

The correct syntax is:

CREATE DATABASE [any unicode string up to 128 characters]

or

CREATE DATABASE "any unicode string up to 128 characters"

More on Database Identifiers: http://msdn.microsoft.com/en-us/library/ms175874.aspx

EDIT:

Here is an example:

CREATE DATABASE [ネット最前線]
 CONTAINMENT = NONE
 ON  PRIMARY 
( NAME = N'ネット最前線_Data', FILENAME = N'C:\temp\ネット最前線_Data.mdf' , SIZE = 209920KB , MAXSIZE = UNLIMITED, FILEGROWTH = 16384KB )
 LOG ON 
( NAME = N'ネット最前線_Log', FILENAME = N'C:\temp\ネット最前線_log.ldf' , SIZE = 768KB , MAXSIZE = UNLIMITED, FILEGROWTH = 10%)
GO
Sign up to request clarification or add additional context in comments.

3 Comments

The collation of an identifier depends on the level at which it is defined. If I understand the document correctly, it's impossible to define identifiers in unicode explicitly by using unicode literals. Correct me if I am wrong.
Collation determines how SQL Server will sort character columns not what type of characters they will store. NCHAR columns can handle unicode chars regardless of collation. The info regarding a database is stored on the master database. Check master.databases name column, it's defined as nvarchar(128). You can specify CREATE DATABASE [ネット最前線] to create a database named ネット最前線, for example.
Collation also determines how SQL Server compares character values (case sensitive vs. insensitive).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.