i want to write a stored procedure in SQL server
that will insert
records to database in which i want to pass table-name and column-names with their values as arguments to the stored procedure.
我想在SQL server中编写一个存储过程,它将向数据库中插入记录,我想在其中传递表名和列名,它们的值作为存储过程的参数。
i am using asp.net three-tier technology if that helps.
如果有帮助的话,我正在使用asp.net三层技术。
if it's impossible than please tell me some alternatives. thanks in advance
如果不可能的话,请告诉我一些替代方案。谢谢提前
3 个解决方案
#1
0
The best answer is "Don't Do That!"
最好的回答是“不要那样做!”
A relational database is best used for modelling.... relationships and to do that you need to have bounds and a design about what data you are going to store. That means that you (or your ORM) will know what the underlying tables look like.
关系数据库是最好的用于造型....要做到这一点,你需要有界限和关于你要存储什么数据的设计。这意味着您(或您的ORM)将知道底层表是什么样子的。
If you want a place to simply throw objects at then think about using a nosql document store like MongoDB instead.
如果您想要一个简单地抛出对象的地方,那么可以考虑使用类似MongoDB的nosql文档存储。
#2
0
Build your SQL in a NVARCHAR dynamically, and pass it to stored procedure sp_executesql:
动态地在NVARCHAR中构建SQL,并将其传递给存储过程sp_executesql:
DECLARE @sql NVARCHAR(MAX);
-- build your SQL in the NVARCHAR
EXEC sp_executesql @sql;
#3
0
This is possible in theory but I’m afraid that’s not really the best solution.
这在理论上是可能的,但恐怕这不是最好的解决办法。
Issues with this approach is that you don’t know many parameters upfront such as column names, how many column names exist, what is their type and such.
这种方法的问题是您不知道很多参数,比如列名、有多少列名、它们的类型是什么等等。
This means that you would have to pass parameters as some default type for example nvarchar and then convert this type to specific column type which can lead to performance and other issues.
这意味着您必须将参数作为默认类型(例如nvarchar)传递,然后将该类型转换为特定的列类型,这会导致性能和其他问题。
I’d suggest you try using Entity framework or some other ORM tool to handle inserts for you.
我建议您尝试使用实体框架或其他ORM工具来为您处理插入。
#1
0
The best answer is "Don't Do That!"
最好的回答是“不要那样做!”
A relational database is best used for modelling.... relationships and to do that you need to have bounds and a design about what data you are going to store. That means that you (or your ORM) will know what the underlying tables look like.
关系数据库是最好的用于造型....要做到这一点,你需要有界限和关于你要存储什么数据的设计。这意味着您(或您的ORM)将知道底层表是什么样子的。
If you want a place to simply throw objects at then think about using a nosql document store like MongoDB instead.
如果您想要一个简单地抛出对象的地方,那么可以考虑使用类似MongoDB的nosql文档存储。
#2
0
Build your SQL in a NVARCHAR dynamically, and pass it to stored procedure sp_executesql:
动态地在NVARCHAR中构建SQL,并将其传递给存储过程sp_executesql:
DECLARE @sql NVARCHAR(MAX);
-- build your SQL in the NVARCHAR
EXEC sp_executesql @sql;
#3
0
This is possible in theory but I’m afraid that’s not really the best solution.
这在理论上是可能的,但恐怕这不是最好的解决办法。
Issues with this approach is that you don’t know many parameters upfront such as column names, how many column names exist, what is their type and such.
这种方法的问题是您不知道很多参数,比如列名、有多少列名、它们的类型是什么等等。
This means that you would have to pass parameters as some default type for example nvarchar and then convert this type to specific column type which can lead to performance and other issues.
这意味着您必须将参数作为默认类型(例如nvarchar)传递,然后将该类型转换为特定的列类型,这会导致性能和其他问题。
I’d suggest you try using Entity framework or some other ORM tool to handle inserts for you.
我建议您尝试使用实体框架或其他ORM工具来为您处理插入。