I have records from server that I want to copy, so I used datareader to select all, during selection the insert also process. This is the pseudo code:
while datareader.read
For f As Integer = 0 To datareader.FieldCount - 1
Values = Values & datareader.GetValue(f)
Next
Dim ss as string ="Insert into xtable(a,b,c,d,e,f) select " & values & " where not Exist (select * from xtable)" ''//is this right?
Dim sc as new sqliteCommand(ss,mycon)
sc.ExecuteNonQuery
End While
sc.dispose
What is the exact sql statement to insert only if record doesn't exist in my current table?
I used some of this code, but a filter was defined: like x What if I just want to insert records that doesn't exist in the table I want.
Dim ss As String = "insert into xtable(x,y,z) select $x, $y,$z
where not exists (select 1 from xtable where x=$x)"
Try this:
if not exists(select 1 from xtable)
begin
insert into xtable(x,y,z) select $x, $y,$z from xtable
end
I don't think the above will work, but this link should give you the answer you're looking for.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.