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.
Asked
Active
Viewed 59 times
-5
-
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 Answers
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
-
2That'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