我有一个具有结构的表:
CREATE TABLE [dbo].[CompanyGeoLocationInfo](
[Id] [bigint] NOT NULL,
[CompanyId] [bigint] NOT NULL,
[Geocode] [geography] NOT NULL,
[GeocodeText] [varchar](100) NOT NULL,
[StateGroupId] [int] NOT NULL,
[ZipCode] [nvarchar](10) NOT NULL,
CONSTRAINT [PK_CompanyGeoLocationInfo] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
我想知道是否有办法在Geocode
列上定义空间索引并在StateGroupId
列上创建分区
最初,我的表在Id
上只有一个主要的culstered索引。首先,我首先尝试在StateGroupId
列上创建分区。脚本是:
BEGIN TRANSACTION
CREATE PARTITION FUNCTION [StateGroupPF](int) AS RANGE LEFT FOR VALUES (N'1', N'2', N'3', N'4', N'5', N'6', N'7', N'8', N'9', N'10', N'11', N'12', N'13', N'14', N'15', N'16', N'17', N'18', N'19', N'20', N'21', N'22', N'23', N'24', N'25', N'26', N'27', N'28', N'29', N'30', N'31', N'32', N'33', N'34', N'35', N'36', N'37', N'38', N'39', N'40', N'41', N'42', N'43', N'44', N'45', N'46', N'47', N'48', N'49', N'50', N'51', N'52', N'53', N'54', N'55', N'56', N'57', N'58')
CREATE PARTITION SCHEME [StateGroupPS] AS PARTITION [StateGroupPF] TO ([PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY])
ALTER TABLE [dbo].[CompanyGeoLocationInfo] DROP CONSTRAINT [PK_CompanyGeoLocationInfo]
ALTER TABLE [dbo].[CompanyGeoLocationInfo] ADD CONSTRAINT [PK_CompanyGeoLocationInfo] PRIMARY KEY NONCLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
CREATE CLUSTERED INDEX [ClusteredIndex_on_StateGroupPS_635860762633977740] ON [dbo].[CompanyGeoLocationInfo]
(
[StateGroupId]
)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [StateGroupPS]([StateGroupId])
DROP INDEX [ClusteredIndex_on_StateGroupPS_635860762633977740] ON [dbo].[CompanyGeoLocationInfo]
COMMIT TRANSACTION
然后,我尝试定义空间索引。错误类似于“对于空间索引,表应具有主聚集索引”。
其次,我首先在Geocode列上定义空间索引,而不是尝试创建分区。这次我得到“无法删除主键约束'PK_CompanyGeoLocationInfo',因为该表具有XML或空间索引。” 错误。
是否有任何直接或解决方法?