创建内存表时出错

时间:2014-10-27 01:13:03

标签: sql sql-server sql-server-2014

我正在尝试在内存中创建一个表,但它一直给我错误,如:

  

Msg 10794,Level 16,State 85,Line 11索引选项'pad_index'是   内存优化表上的索引不支持。

另一个人对Primary Key Clustered说了同样的话。

上面的两件事(pad_index和PK Clustered)是必需的,除非有另一种方法让它工作......

[DEMO-Training1] 
GO

/****** Object: Table [dbo].[wtAssetChildren] ******/ 
SET ANSI_NULLS ON GO

SET QUOTED_IDENTIFIER ON GO

CREATE TABLE [dbo].[wtAssetChildren] ( 
  [wtAssetChildrenID] [int] IDENTITY(1,1) NOT NULL, 
  [wtGUID] [uniqueidentifier] NOT NULL, 
  [CallingAssetID] [int] NOT NULL, 
  [AssetID] [int] NOT NULL, 
  [Processed] [bit] NOT NULL, 
  CONSTRAINT [PK_wtAssetChildren] PRIMARY KEY CLUSTERED ([wtAssetChildrenID] ASC)
  WITH (
    PAD_INDEX = OFF, 
    STATISTICS_NORECOMPUTE = OFF, 
    IGNORE_DUP_KEY = OFF, 
    ALLOW_ROW_LOCKS = ON, 
    ALLOW_PAGE_LOCKS = ON
  ) ON [PRIMARY] 
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[wtAssetChildren] 
ADD CONSTRAINT [DF_wtAssetChildren_Processed] DEFAULT ((0)) FOR [Processed] GO

2 个答案:

答案 0 :(得分:0)

内存中OLTP表相对于MS SQL附带的其他内容有一些限制。查看http://msdn.microsoft.com/en-us/library/dn246937.aspx以获取完整列表。

例如,不支持群集PK。您将不得不使用非聚集主键索引。

答案 1 :(得分:0)

以下是如何在内存优化的SQL Server 2014中创建此表的示例。请注意,仅仅因为您可以,并不意味着您应该这样做。你提到你是初学者,内存优化表更像是一个高级选项。

CREATE DATABASE MemoryOptimizedTest;
GO

ALTER DATABASE MemoryOptimizedTest
    ADD FILEGROUP MemoryOptimizedTest_MemoryOptimized
    CONTAINS MEMORY_OPTIMIZED_DATA;
GO

ALTER DATABASE MemoryOptimizedTest 
    ADD FILE (
          NAME = 'MemoryOptimizedTest__MemoryOptimized1'
        , FILENAME = 'D:\SqlDataFiles\MemoryOptimizedTest__MemoryOptimized1') 
    TO FILEGROUP MemoryOptimizedTest_MemoryOptimized;
GO

ALTER DATABASE MemoryOptimizedTest
    SET MEMORY_OPTIMIZED_ELEVATE_TO_SNAPSHOT=ON;
GO

USE MemoryOptimizedTest;
GO

CREATE TABLE [dbo].[wtAssetChildren](
       [wtAssetChildrenID] [int] IDENTITY(1,1) NOT NULL
     , [wtGUID] [uniqueidentifier] NOT NULL
     , [CallingAssetID] [int] NOT NULL
     , [AssetID] [int] NOT NULL
     , [Processed] [bit] NOT NULL
        CONSTRAINT [DF_wtAssetChildren_Processed] DEFAULT ((0))
     , CONSTRAINT [PK_wtAssetChildren] PRIMARY KEY NONCLUSTERED( [wtAssetChildrenID] ASC )
     )
WITH (MEMORY_OPTIMIZED=ON, DURABILITY=SCHEMA_AND_DATA);