如何在存储过程中动态传递参数 [英] How do I pass parameters dynamically in a stored procedure

查看:201
本文介绍了如何在存储过程中动态传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一种情况,应该动态加载表单以及数据库中的表.我需要使用存储过程将数据保存在数据库中.如何将动态参数传递给存储过程

我尝试过的事情:

我已经向表动态创建了添加的列,已经创建了表格,现在我必须保存数据

Hi guys,
I have a scenario that a form should be loaded dynamically and also the table in database.I need to save the data in the database using stored procedure.How to pass dynamic parameter to the store procedure

What I have tried:

I have created added columns dynamically to the table,I have created the form,now I have to save the data

推荐答案

如果我正确理解了您的问题,则可以通过表和列名,例如在过程的两个单独参数中,然后在过程中构建语句并使用 ^ ].

但是,如果动态创建表及其列,总是听起来有点可疑.数据库中的大多数表本质上都是永久性的.因此,检查数据库设计是否可以避免动态表可能是一个好主意.
If I understand your question correctly, you can pass the table and column names for example in two separate parameters to the procedure and then build the statement in the procedure and execute it using EXECUTE (Transact-SQL) | Microsoft Docs[^] .

However, it always sounds a bit suspicious if a table and it''s columns are created dynamically. Most of the tables in the database are permanent in nature. So it maybe a good idea to check the database design if the dynamic table can be avoided.


这篇关于如何在存储过程中动态传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆