简体   繁体   English

将SQL Server排序规则从区分大小写更改为不区分大小写?

[英]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.

相关问题 SQL Server 2005在不区分大小写的情况下执行区分大小写的排序 - Sql server 2005 acting case sensitive inspite of case insensitive collation 如果sql server的服务器排序规则区分大小写并且数据库不区分大小写,那么查询是否区分大小写? - If a sql server's server collation is case sensitive and a database is case-insensitive, will queries be case-sensitive or not? SQL Server不区分大小写的排序规则 - SQL Server case insensitive collation 区分大小写的数据库排序规则,但不区分大小写的SQL查询 - Case-sensitive database collation, but case-insensitive SQL queries SQL Server排序规则和不区分大小写的标识符 - SQL Server Collation And Case Insensitive Identifiers 在区分大小写的 SQL Server 数据库中执行不区分大小写的 Like 查询 - Perform a Case insensitive Like query in a case sensitive SQL Server database SQL Server Collat​​ion匹配Java不区分大小写的Unicode比较 - SQL Server Collation to match Java case insensitive Unicode compare SQL Server:排序规则不区分大小写时的不明确的排序顺序 - SQL Server: Ambiguous sort order when collation is case-insensitive SQL Server 在列级别设置区分大小写的排序规则 - SQL Server case-sensitive collation at column level settings 如何在SQL Server中获取一个区分大小写的排序规则版本? - How to get a case sensitive version of a collation in SQL Server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM