简体   繁体   中英

How do I determine the collation of a database in SQL 2005?

例如,如果需要执行不区分大小写的搜索/替换,如何确定SQL 2005中数据库的排序规则?

使用以下SQL确定数据库的排序规则:

SELECT DATABASEPROPERTYEX('{database name}', 'Collation') SQLCollation;

Remember, that individual columns can override the database collation:

SELECT TABLE_NAME, COLUMN_NAME, COLLATION_NAME
FROM INFORMATION_SCHEMA.COLUMNS

If you want to do a case-insensitive search and can't rely on the database's collation, you could always specifically request it for the query you're interested in. For instance:

SELECT TOP 1 FName, *
FROM People
WHERE FName LIKE '%mich%' COLLATE Latin1_General_CI_AI

I usually have the opposite problem, where I want the case sensitivity but don't have it in the database's collation, so I find myself using the Latin1_General_BIN collation quite a bit in my queries. If you don't already know, you can do:

SELECT 
FROM ::fn_helpcollations()

for a list of the available collations and descriptions of what they're for.

选择数据库并运行以下命令。

sp_helpsort

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM