0
我對SQL不熟悉。我試圖插入多行數據到表中,如果在BusinessFilterPhrase
列中存在具有重複值的行,則不要插入。我寫了一個我認爲應該是的東西的僞代碼。將多行唯一行插入表
if (filterCategoryList != null)
{
foreach (KeyValuePair<string, int> filter in filterCategoryList)
{
cmd.CommandText = "insert into tblBusinessName (BusinessFilterPhrase,BusinessCategoryID)" +
"select @BusinessFilterPhrase,@BusinessCategoryID" +
"from tblBusinessName as t1" +
"where NOT EXISTS" +
"(select * from tblBusinessName as d1 where d1.BusinessFilterPhrase = @BusinessFilterPhrase) ";
cmd.Parameters.AddWithValue("@BusinessFilterPhrase", filter.Key);
cmd.Parameters.AddWithValue("@BusinessCategoryID", filter.Value.ToString());
cmd.ExecuteNonQuery();
}
}
有沒有另外一種方式可以在查詢進入像500>插入時更好地擴展?例子?加入? –