下面的图片是2008年 R2系统视图 Microsoft SQL Server 的一部分。从图像中我们可以看到,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,等级15,状态1,第6行’=’附近语法不正确。

 
                                
                             
                                
                             
                                
                             
                                
                             
                                
                             
                                
                             
                                
                             
                                
                             
                                
                            