我有一个C#RestApi,它需要通过执行如下查询来使用ADO从数据库中提取记录的信息:
declare @id1 int
set @id1 = (select id from myTable where col1= x1, col2 = y1, col3 = z1 from mappingTable)
declare @id2 int
set @id2 = (select id from myTable where col1= x2, col2 = y2, col3 = z2 from mappingTable)
declare @id3 int
set @id3 = (select id from myTable where col1= x3, col2 = y3, col3 = z3 from mappingTable)
.
.
.
declare @idN int
set @idN = (select id from myTable where col1= xN, col2 = yN, col3 = zN from mappingTable)
select @id1,@id2,@id3, ..., @idN
我在上面运行的查询中使用ADO.NET SqlCommand
在其中运行N个查询并读取结果。我有两个问题:
SqlCommand
运行每个查询是否会导致性能下降?通常,在I / O任务中,执行许多小型I / O任务的性能要比在一批I / O任务中运行所有小I / O任务的性能低,但是我不知道在Databases和ADO中是否存在相同的情况。注意:在上面的查询中,所有查询中的列和表都相同,只是对where子句中的值进行了修改。
使用表值参数来存储x
,y
和z
的相应值。使用单个查询,在其中将mappingTable
与该表值参数进行内部联接。