-5

I have been parsing data. I receive data and compare them with the data in my database. Which command should I use so that only non-existing data can be inserted? I.i if some data already exists in the database, then nothing should be inserted.

jon hanson
  • 8,722
  • 2
  • 37
  • 61
  • Do you plan to write C# code using ADO.net or a stored procedure on the database side? – RBT Jun 18 '16 at 10:37

1 Answers1

0

You can check existence of data in sql using if exists.

if you want to insert data which is already not in table you can use something like this.

Let say its a users table

if not exists(select 1 from tbluser where Userid = 1)
 Insert into tbluser(col1,col2,col3) values (val1,val2,val3)

You can add other columns in where condition using and if required.

Mairaj Ahmad
  • 14,434
  • 2
  • 26
  • 40
  • 2
    That's fine for one row, but the OP seems to be looking for the `MERGE` statement, or `WHERE NOT EXISTS`. – CodeCaster Jun 18 '16 at 10:42