How to pass large number of parameters in stored procedure from code to SQL Server

前端 未结 4 1551
情话喂你
情话喂你 2021-01-24 05:13

How to pass a large number of parameters (say 20+) to stored procedure from code?

Like we can group all the parameters in one class object and then pass it across, but h

4条回答
  •  情话喂你
    2021-01-24 05:51

    If you are using SQL Server 2008, use a table-valued parameter. If you are not familiar, it basically allows you to pass a table as a param to a stored procedure. The benefit is that you can structure the DataTable you pass in to look however you want.

    I did something like this and instead of passing dozens of params, I passed in a single TVP with two columns [KEY] and [VALUE]. That way when your parameters change in the future, there exists a layer of abstraction to insulate the migration. Of course, how you choose to implement it depends on the situation.

提交回复
热议问题