2011-01-22 43 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

相關問題