我的数据库表 ( Medicines
) 中有以下列。
ID bigint,
MedicineName nvarchar(50),
BrandName nvarchar(50),
MedicineCode nvarchar(20),
and price,quantity.
Run Code Online (Sandbox Code Playgroud)
我正在使用此查询创建存储过程:
create proc searchmedicine
@name nvarchar(50)=null,@brand nvarchar(50)=null, @code nvarchar(20)=null
as
select * from Medicines
where MedicineName= Case WHEN @name IS NOT NULL THEN @name ELSE MedicineName END
AND BrandName=Case WHEN @brand IS NOT NULL THEN @brand ELSE BrandName END
AND MedicineCode=Case WHEN @code IS NOT NULL THEN @code ELSE MedicineCode END
Run Code Online (Sandbox Code Playgroud)
现在我很困惑哪个非聚集索引更适合帮助优化查询:复合列还是单列?