I am using pyodbc to update an Access database.

I need the functionality of an UPSERT.

`ON DUPLICATE KEY UPDATE` doesn't exist in Access SQL, and `REPLACE` is not an option since I want to keep other fields.

There are a lot of suggestions out there how to solve that, so this is
the solution which I put together:

```
for table_name in data_source:
    table = data_source[table_name]

    for y in table:
        if table_name == "whatever":
            SQL_UPDATE = "UPDATE {} set [Part Name] = '{}', [value] = {}, [code] = {}, [tolerance] = {} WHERE [Unique Part Number]='{}'".\
                format(table_name,y['PartName'],y['Value'],y['keycode'],y['Tolerance'], y['PartNum'])
            SQL_INSERT = "INSERT INTO {} ([Part Name],[Unique Part Number], [value], [code], [tolerance]) VALUES ('{}','{}','{}',{},{},{});".\
                format(table_name,y['PartName'],y['PartNum'],y['Value'],y['keycode'],y['Tolerance'])
        elsif ....
                9 more tables....

       res = cursor.execute(SQL_UPDATE)
       if res.rowcount == 0:
         cursor.execute(SQL_INSERT)

```

Well I have to say, I am not a Python expert, and I didn't manage to understand the fundamental concept nor the Magic of SQL,
 so I can just Google things together here.

I don't like my above solution because it is very hard to read and difficult to maintain (I have to to this for ~10 different tables). The other point is that I have to use 2 queries because I didn't manage to understand and run any other UPSERT approach I found.

Does anyone have a recommendation for me how to do this in a smarter, better maintainable way?