我有以下观点
create view V(CategoryId, ...)
as
select 1, .... from T1 union all
select 2, .... from T2 union all
select 3, .... from T3 union all
select 4, .... from T4 union all
select 5, .... from T5 union all
...
我没有将列添加CategoryId
到下划线表中,因为每个表都有常量值,因此我无法添加,Check(CategoryId = 1)
因为该列实际上并不存在。
以下查询将扫描所有表。是否可以让执行计划只扫描一个表以进行查询?
declare @id tinyint = (....);
select * from V where CategoryId = @id and ...