[英]Changing SQL Server collation to case insensitive from case sensitive?
I've recently installed SQL Server 2008 and I selected collation as case sensitive. 我最近安装了SQL Server 2008,并且选择排序规则为区分大小写。 I want to make it case insensitive for the entire instance (not for a database in that instance).
我想使整个实例不区分大小写(而不是该实例中的数据库)。 If I change the collation does it affect any existing databases?
如果更改排序规则,是否会影响任何现有数据库? if so in what way?
如果真是这样,那么是以哪种方式?
You basically need to run the installation again to rebuild the master
database with the new collation. 基本上,您需要再次运行安装以使用新的排序规则重建
master
数据库。 You cannot change the entire server's collation any other way. 您无法通过其他任何方式更改整个服务器的排序规则。
See: 看到:
Update: if you want to change the collation of a database, you can get the current collation using this snippet of T-SQL: 更新:如果要更改数据库的排序规则,则可以使用以下T-SQL代码片段获取当前的排序规则:
SELECT name, collation_name
FROM sys.databases
WHERE name = 'test2' -- put your database name here
This will yield a value something like: 这将产生类似以下的值:
Latin1_General_CI_AS
The _CI
means "case insensitive" - if you want case-sensitive, use _CS
in its place: _CI
表示“不区分大小写”-如果要区分大小写,请使用_CS
代替:
Latin1_General_CS_AS
So your T-SQL command would be: 因此,您的T-SQL命令为:
ALTER DATABASE test2 -- put your database name here
COLLATE Latin1_General_CS_AS -- replace with whatever collation you need
You can get a list of all available collations on the server using: 您可以使用以下命令获取服务器上所有可用归类的列表:
SELECT * FROM ::fn_helpcollations()
You can see the server's current collation using: 您可以使用以下命令查看服务器的当前排序规则:
SELECT SERVERPROPERTY ('Collation')
You can do that but the changes will affect for new data that is inserted on the database. 您可以执行此操作,但是更改将影响数据库中插入的新数据。 On the long run follow as suggested above.
从长远来看,按照上面的建议。
Also there are certain tricks you can override the collation, such as parameters for stored procedures or functions, alias data types, and variables are assigned the default collation of the database. 另外,还有一些技巧可以覆盖排序规则,例如存储过程或函数的参数,别名数据类型,以及为变量分配数据库的默认排序规则。 To change the collation of an alias type, you must drop the alias and re-create it.
要更改别名类型的排序规则,必须删除别名并重新创建它。
You can override the default collation of a literal string by using the COLLATE clause. 您可以使用COLLATE子句覆盖文字字符串的默认排序规则。 If you do not specify a collation, the literal is assigned the database default collation.
如果您未指定排序规则,则将为字面量分配数据库默认排序规则。 You can use DATABASEPROPERTYEX to find the current collation of the database.
您可以使用DATABASEPROPERTYEX查找数据库的当前排序规则。
You can override the server, database, or column collation by specifying a collation in the ORDER BY clause of a SELECT statement. 通过在SELECT语句的ORDER BY子句中指定排序规则,可以覆盖服务器,数据库或列的排序规则。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.