我正在准备一个新的数据库服务器,我将从一个大的,现有的多语言数据库(主要是英语/法语/西班牙语文本,很少来自其他语言的特殊字符,例如城市名称)迁移数据。 我的问题是:它应该是口音敏感吗? 如果搜索在咖啡馆和咖啡馆之间没有区别,用户会很高兴。 但作为一名DBA,我很担心:我从未见过一个数据库至少偶尔会遇到一次糟糕的字符转换。如果我选择重音不敏感,我将如何查询数据库并询问“给我所有标题包含特殊字符的书籍”? 如果我有办法做到这一点,我会很乐意去解除口音。
答案 0 :(得分:1)
这应该取决于您的一般用法。
这并不排除您为特定查询更改
例如
declare @t1 table (word nvarchar(50) collate Latin1_General_CI_AI)
declare @t2 table (word nvarchar(50) collate Latin1_General_CI_AS)
insert @t1 values ('cafe'),('restaurant'), ('café')
insert @t2 select * from @t1
select * from @t1 where word like 'cafe'
select * from @t1 where word like 'cafe' collate Latin1_General_CI_AS
select * from @t1 where word like 'café'
select * from @t1 where word like 'café' collate Latin1_General_CI_AS
select * from @t2 where word like 'cafe'
select * from @t2 where word like 'cafe' collate Latin1_General_CI_AI
select * from @t2 where word like 'café'
select * from @t2 where word like 'café' collate Latin1_General_CI_AI
答案 1 :(得分:1)
You can change collation at select time:
with t as (
select 'ali' as w union
select 'àli' as w
)
select *
into #t
from t;
select * from #t
where w collate Latin1_General_CS_AS_KS_WS like '%à%'
w
---
àli
select * from #t
where w collate Traditional_Spanish_ci_ai like '%à%'
w
---
ali
àli