2011-01-22 164 views

回答

1

在SQL Server中,一列是否区分大小写或不依赖于你已经应用了什么排序规则。

默认排序有可能是“SQL_Latin1_General_CP1_CI_AS”(CI是“不区分大小写”)。如果您更改数据库模式,以便列具有排序规则“SQL_Latin1_General_CP1_CS_AS”,那么对其进行查询将区分大小写。

+0

谢谢,那正是我所期待的。 – 2011-01-22 03:30:41

2

你不需要改变你的数据库 您可以修改您的查询工作区分大小写:

SET NOCOUNT ON 
declare @curdb sysname; select @curdb = db_name(0); 
select DATABASEPROPERTYEX(@curdb, 'Collation') Collation; 

if object_id('test_CI', 'U') is not null 
    drop table test_CI 
go 

create table test_CI (
    val varchar(10) 
    ); 
go 
insert into test_CI values ('TEST');  
insert into test_CI values ('Test');  
insert into test_CI values ('test');  

-- 
select * from test_CI where val = 'Test'; 

select * from test_CI where val collate Latin1_General_CS_AS = 'Test'; 

只需使用您的当前排序顺序,并通过CS更换CI。

+0

+1表示强制大小写的比较方式 – RichardTheKiwi 2011-01-22 23:20:31

相关问题