1

我正在将一些表和存储过程迁移到内存优化表和本机编译的存储过程。我被困在字符串比较上。

本机编译的存储过程不支持对不使用 *_BIN2 排序规则的字符串进行比较、排序和操作。

CREATE TABLE [User].[FingerPrints]
(
    Id int NOT NULL PRIMARY KEY NONCLUSTERED HASH WITH (BUCKET_COUNT = 10000),
    FingerPrint VARCHAR(4000) NOT NULL,
    SecretKey VARCHAR(512) NOT NULL,
    BranchId int NOT NULL,
    SteadySign bit NOT NULL,
    CreatedOn datetime NOT NULL,
    ModifiedOn datetime NOT NULL
) WITH (MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_AND_DATA)
GO

CREATE PROCEDURE [User].[GetFingerPrint]
    @Id int,
    @SecretKey VARCHAR(512)
WITH NATIVE_COMPILATION, SCHEMABINDING, EXECUTE AS OWNER
AS BEGIN ATOMIC WITH
(
 TRANSACTION ISOLATION LEVEL = SNAPSHOT, LANGUAGE = N'us_english'
)

SELECT [Id]
      ,[FingerPrint]
      ,[SecretKey]
      ,[BranchId]
      ,[SteadySign]
      ,[CreatedOn]
      ,[ModifiedOn]
  FROM [User].[FingerPrints]
  WHERE [Id] = @Id AND [SecretKey] = @SecretKey

END
GO
4

1 回答 1

3

在 AdventureWorks2014 的副本中,更改参数的排序规则@SecretKey似乎对我有用:

CREATE PROCEDURE [User].[GetFingerPrint]
    @Id int,
    @SecretKey VARCHAR(512) 
    WITH NATIVE_COMPILATION, SCHEMABINDING, EXECUTE AS OWNER
AS BEGIN ATOMIC WITH
(
 TRANSACTION ISOLATION LEVEL = SNAPSHOT, LANGUAGE = N'us_english'
)

SELECT [Id]
      ,[FingerPrint]
      ,[SecretKey]
      ,[BranchId]
      ,[SteadySign]
      ,[CreatedOn]
      ,[ModifiedOn]
  FROM [User].[FingerPrints]
  WHERE [Id] = @Id AND [SecretKey] = @SecretKey COLLATE LATIN1_GENERAL_BIN2

END
GO
于 2016-02-17T18:40:16.493 回答