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.
-
1strings 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.Damien_The_Unbeliever– Damien_The_Unbeliever2014-01-15 13:36:20 +00:00Commented Jan 15, 2014 at 13:36
-
What do you want to accomplish? Create a database with a dynamic name?usr– usr2014-01-15 13:51:13 +00:00Commented Jan 15, 2014 at 13:51
-
possible duplicate of Create a database with dynamic database name in sql server 2005usr– usr2014-01-15 13:51:46 +00:00Commented Jan 15, 2014 at 13:51
Add a comment
|
1 Answer
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
3 Comments
Kai
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.
Wagner DosAnjos
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.Wagner DosAnjos
Collation also determines how SQL Server compares character values (case sensitive vs. insensitive).