SQL Server 中的默认排序规则类型允许针对不区分大小写的字符串进行索引,但数据的大小写仍然保留。这实际上是如何工作的?我正在寻找实际的具体细节、位和字节,或详细解释它的好资源。
create table casetest (fruitnames nvarchar(50) not null);
create unique index IX_fruitnames on casetest(fruitnames);
insert into casetest values ('apples');
insert into casetest values ('Pears');
-- this insert fails
insert into casetest values ('pears');
-- this yields 'Pears' as a result
select * from casetest (forceseek) where fruitnames = 'PEARS'
update casetest set fruitnames = 'pears' where fruitnames = 'pEArs'
-- this yields 'pears' as a result
select * from casetest (forceseek) where fruitnames = 'PEARS'
Run Code Online (Sandbox Code Playgroud)
有谁知道解决方法?本质上,即使行不符合条件,存储过程也会对索引视图强制插入运算符。因此,存在强制转换错误。但是,对于临时用户,sql 正确地将视图排除在外。
考虑以下模式:
create table testdata (
testid int identity(1,1) primary key
, kind varchar(50)
, data nvarchar(4000))
go
create view integer_testdata with schemabinding
as
select cast(a.data as int) data, a.kind, a.testid
from dbo.testdata a
where a.kind = 'integer'
go
create unique clustered index cl_intdata on integer_testdata(data)
go
create procedure insert_testdata
(
@kind varchar(50)
, @data nvarchar(4000)
)
as
begin
insert into testdata (kind, data) values (@kind, @data)
end
go
Run Code Online (Sandbox Code Playgroud)
这些都有效:
insert into testdata (kind, data) values ('integer', '1234');
insert …
Run Code Online (Sandbox Code Playgroud) Phone
SQL Server 在唯一索引中将它们视为相同的下面插入的值是什么意思?
CREATE TABLE Phone
(
Id int identity(1, 1) primary key,
Phone nvarchar(448) not null
)
go
create unique index IX_Phone on Phone(Phone)
with (data_compression = page);
go
insert into Phone Values ('?281/?263-?8400');
insert into Phone Values ('?281/?263-?8400');
select * from Phone;
drop table Phone;
Run Code Online (Sandbox Code Playgroud)
我收到一条错误消息:
消息 2601,级别 14,状态 1,第 13 行无法在唯一索引为“IX_Phone”的对象“dbo.Phone”中插入重复的键行。重复的键值为 (?281/?263-?8400)。