1. First off, you can see if a table has a primary key with the sys.indexes view, e.g.select OBJECT_NAME(object_id), * from sys.indexes where is_primary_key = 1
but how do you know which field in the csv file has the primary key?You can do a conditional insert/update. Assuming you have loaded your csv file to a table:updated tableaset col1 = csv.col1from tableajoin csv on tablea.pk = csv.pk
2. use a WHERE clause that matches all the columns instead of just the PK3. Conditional insert:insert into tablea(...)select * from csvwhere not exists ( select 1 from tablea where csv.col1 <> tablea.col2 or csv.col2 <> tablea.col1, ...)