让SQLServer like查询大小写敏感

CREATE TABLE [Table7] (
[string] [varchar] (50) COLLATE Chinese_PRC_CI_AI NULL ,
[curdate] [datetime] NOT NULL CONSTRAINT [DF_Table7_curdate] DEFAULT (getdate())
) ON [PRIMARY]
GO

insert table7(string,curdate) values( 'a12'   ,    '2002-08-27 17:21:05.140' )
insert table7(string,curdate) values( 'A21'  ,    '2002-08-27 17:21:07.433' )
insert table7(string,curdate) values( 'aaa'    ,    '2002-08-27 17:21:18.097' )
insert table7(string,curdate) values( 'Asss'  ,    '2002-08-27 17:21:23.917' )
insert table7(string,curdate) values( 'sAs'   ,    '2002-08-27 17:21:26.140' )
insert table7(string,curdate) values( 'aaaaaq'  ,    '2002-08-27 17:21:28.240' )
insert table7(string,curdate) values( 'xxxa'  ,    '2002-08-27 17:21:32.307' )
insert table7(string,curdate) values( '121A'  ,    '2002-09-05 14:34:11.910' )
go

SELECT          *
FROM            Table7

string                                             curdate                                                
-------------------------------------------------- ------------------------------------------------------ 
a12                                                2002-08-27 17:21:05.140
A21                                                2002-08-27 17:21:07.433
aaa                                                2002-08-27 17:21:18.097
Asss                                               2002-08-27 17:21:23.917
sAs                                                2002-08-27 17:21:26.140
aaaaaq                                             2002-08-27 17:21:28.240
xxxa                                               2002-08-27 17:21:32.307
121A                                               2002-09-05 14:34:11.910

(8 row(s) affected)


--字符集是Chinese_PRC_CI_AI,大小写不敏感

SELECT          *
FROM            Table7
WHERE           (string LIKE '%a%')

string                                             curdate                                                
-------------------------------------------------- ------------------------------------------------------ 
a12                                                2002-08-27 17:21:05.140
A21                                                2002-08-27 17:21:07.433
aaa                                                2002-08-27 17:21:18.097
Asss                                               2002-08-27 17:21:23.917
sAs                                                2002-08-27 17:21:26.140
aaaaaq                                             2002-08-27 17:21:28.240
xxxa                                               2002-08-27 17:21:32.307
121A                                               2002-09-05 14:34:11.910

(8 row(s) affected)

--改变字符集

alter table table7 ALTER COLUMN string varchar(50) COLLATE Chinese_PRC_CS_AI
go

--字符集是Chinese_PRC_CS_AI,大小写敏感

SELECT          *
FROM            Table7
WHERE           (string LIKE '%a%')

string                                             curdate                                                
-------------------------------------------------- ------------------------------------------------------ 
a12                                                2002-08-27 17:21:05.140
aaa                                                2002-08-27 17:21:18.097
aaaaaq                                             2002-08-27 17:21:28.240
xxxa                                               2002-08-27 17:21:32.307

(4 row(s) affected)

--改变字符集

alter table table7 ALTER COLUMN string varchar(50) COLLATE Chinese_PRC_CI_AI
go

--字符集是Chinese_PRC_CI_AI,大小写不敏感

string                                             curdate                                                
-------------------------------------------------- ------------------------------------------------------ 
a12                                                2002-08-27
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值