以下图片是 Microsoft SQL Server 2008 R2 系统视图的一部分。从图片中我们可以看到 sys.partitions
和 sys.allocation_units
之间的关系取决于 sys.allocation_units.type
的值。因此,为了将它们连接起来,我会写出类似于这样的代码:
SELECT *
FROM sys.indexes i
JOIN sys.partitions p
ON i.index_id = p.index_id
JOIN sys.allocation_units a
ON CASE
WHEN a.type IN (1, 3)
THEN a.container_id = p.hobt_id
WHEN a.type IN (2)
THEN a.container_id = p.partition_id
END
但是上面的代码会出现语法错误。我猜这是由于CASE
语句引起的。有人可以帮忙解释一下吗?
添加错误信息:
Msg 102,Level 15,State 1,Line 6 Incorrect syntax near '='.