I have a C# RestApi which need to extract information of records from database using ADO by executing queries like this:
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
I run above query which runs N queries inside it using ADO.NET SqlCommand and read the results. I have two questions:
- Does running each of queries using separate
SqlCommandlead to performance downgrade or not? Usually in I/O tasks, executing many small I/O tasks have lower performance than running all of them in one batch I/O tasks but I have no idea about the same scenario in Databases and ADO. - Are there any better ways to extract the same result with a better SQL query? In other words can I write this query other way to run it with better performance?
Note: In above queries columns and tables are the same in all queries only values in where clause are modified.