asp.net - Insert mutiple unique rows into a table -


I am not familiar with SQL as much as I'm trying to insert multiple rows of data in a table, if No line exists BusinessFilterPhrase duplicate values ​​in the column, do not just insert. I

  if (filterCategoryList = null!) {Foreach (KeyValuePair & LT; string, filter the integer & gt; filterCategoryList). {Insert Cmd.CommandText = "tblBusinessName (BusinessFilterPhrase, BusinessCategoryID) selected tblBusinessName as" + "t1 @ BusinessFilterPhrase, @ BusinessCategoryID" + "" + "is not the" + "(select * as d1 from tblBusinessName Where d1.BusinessFilterPhrase = @BusinessFilterPhrase) "; Cmd.Parameters.AddWithValue ("@FilterFilterPhrase", filter.Key); Cmd.Parameters.AddWithValue ("@ BusinessCategoryID", Filters. Value.ToString ()); Cmd.ExecuteNonQuery (); }}    

Your code looks right as I wrote it:

  tblBusinessName (BusinessFilterPhrase, BusinessCategoryID) select @BusinessFilterPhrase, putting @BusinessCategoryID does not exist where tblBusinessName t1 (select 1 from tblBusinessName d1 where d1.BusinessFilterPhrase = @BusinessFilterPhrase)   

(changes are only cosmetic.)

edit:

If performance is an issue, but BusinessFilterPhrase create an index :

  index idx_tblBusinessName_B on tblBusinessName (BusinessFilterPhrase) Create usinessFilterPhrase;   

You can make it a is index, if you want the database to enforce uniqueness of the column will put duplicate values ​​(if this is an error Will generate).

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -