一个查询插入多行我的userIds
与使用C#阵列
List<int> userIds = new List<int>();
我有代码中插入它们到分贝的列表。
ExecuteSQL(sql)
是我自己的函数,抽象了所有的数据库特定的逻辑
string iSql = "";
foreach(int id in userIds){
iSql = "insert into users (id) values (" + id + ")";
ExecuteSQL(iSql);
}
我想插入所有这些在一个查询,而不必调用像上面的循环, 这可能在SQL?
如果是这样,那么string iSql
会是什么样子?
我发现Inserting multiple rows in a single SQL query?,
但可能创造一个大的字符串。
,我发现其他文章要么其他语言或只是困惑,因为我无法它们与我的问题
(后来我才可以照顾参数的,我只需要查询)
当你得到了一些答案,我认为1000使用可以插入了值(1),(2)。如果超过1000则可以使用TVP。 http://msdn.microsoft.com/en-us/library/bb510489.aspx – Paparazzi
参考http://lennilobel.wordpress.com/2009/07/29/sql-server-2008-table-valued-parameters-and -C-定制迭代器-A-比赛做在天堂/ – Paparazzi