我读过的所有内容都说这不应该发生,但它确实发生了。我的数据库大小大约为 15GB,有几百个表,表可以有几行到几百万不等的任何地方。
以下是发生的情况:假设我有一个名为的表orders
,第一列被调用ID
并且是表的主键。还有许多其他列,其中之一名为policy
. 如果我运行以下查询:
SELECT *
FROM orders
WHERE policy = 12345
ORDER BY ID
我希望结果看起来像这样:
1
2
3
4
5
6
但有时结果会如下所示:
1
2
4
5
3
6
就好像3
被移到了不同的位置。这如何/为什么会发生?
实际查询是
SELECT * FROM loc_info WHERE PolInfo_ID=25634 ORDER BY LocInfo_ID
表定义为
CREATE TABLE [dbo].[loc_info](
[LocInfo_ID] [int] IDENTITY(1,1) NOT NULL,
[PolInfo_ID] [int] NOT NULL,
[name] [varchar](100) NOT NULL,
[address1] [varchar](100) NULL,
[address2] [varchar](100) NULL,
[city] [varchar](100) NULL,
[state] [varchar](100) NOT NULL,
[zip] [char](10) NULL,
[county] [varchar](100) NULL,
[country] [varchar](100) NULL,
[loc_number] [varchar](20) NULL,
[occ_type_id] [int] NULL,
[occ_type] [varchar](100) NULL,
[flood_zone] [varchar](6) NOT NULL,
[coastal_zone] [varchar](20) NOT NULL,
[earthquake_zone] [varchar](20) NOT NULL,
[earthquake_group] [varchar](20) NULL,
[BuildingTIV] [numeric](18, 0) NULL,
[MachEquipTIV] [numeric](18, 0) NULL,
[StocksSuppliesTIV] [numeric](18, 0) NULL,
[OtherTIV] [numeric](18, 0) NULL,
[BusinessInterruptTIV] [numeric](18, 0) NULL,
[ExtraExpTIV] [numeric](18, 0) NULL,
[RentTIV] [numeric](18, 0) NULL,
[Property] [numeric](18, 0) NULL,
[IsUpload] [bit] NULL,
[IsMoved] [bit] NULL,
CONSTRAINT [PK_locations] PRIMARY KEY CLUSTERED
(
[LocInfo_ID] ASC
)WITH (PAD_INDEX = OFF
, STATISTICS_NORECOMPUTE = OFF
, IGNORE_DUP_KEY = OFF
, ALLOW_ROW_LOCKS = ON
, ALLOW_PAGE_LOCKS = ON
, FILLFACTOR = 90) ON [PRIMARY]
)