How to INSERT if there is no key data in SQL and UPDATE the data in the key if there is one.

Asked 1 years ago, Updated 1 years ago, 65 views

Thank you for your help.

I think it's a question that has been asked many times in the past, but I couldn't find it in the past log, so
Let me ask you a question.

Learn how to import CSV files into an existing table regardless of database type
I'm considering it.

If there is a key in a particular field and CSV-side data does not correspond to table-side keys,
Add data as a new item (Import) and
record contents if applicable I would like to update (UPDATE), but I would like to know how to do this in all databases
Is there a common way to do this?

It would be best if I could collide with CSV directly, but once it's all in the dummy table
You can import and compare ….

I'm not very knowledgeable yet, and according to the current method, I'm not sure if the code side has taken out the data one by one. After comparing them, loop the CSV lines like INSERT or UPDATE for a few minutes.
There are, but this will take a lot of time (150,000 cases).


Database-independent, common SQL scope, one or two of these tasks in SQL I'd like to do it, but could you please let me know if there is any way like that?

Thank you for your cooperation.

sql csv database

2022-09-30 15:02

1 Answers

In the first place, there is no "standard way" to import CSV (e.g., non-DB data) into DB.It makes no sense to stick to the "standard method" because at this point you have to use DB-specific features.

·Straightforwardly processing one line at a time
·After loading into the temporary table in bulk, update the existing table + insert
·Depending on the DB, can you do it at once?

It's up to the product to decide which of these is more efficient, and if possible, it may not be operational (for example, it's not convenient to have a table lock for a long time).


2022-09-30 15:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.