So I posted this question yesterday. Some of the responses I got were helpful, however it seems my issue is a bit more complex than I originally thought.
After doing some looking the reason I was getting errors with my INSERT
statement was because I was having columns like this:
part_number | description | information
------------------------------------------------
331335A11 Desc1 Info1
331335A11 Desc2 Info1
Essentially, there are a number of entries that have the same value for the part_number
field (which is suppose to be a UNIQUE
column) but different vales for their other columns. As such the query was trying to insert them into the database, and I have my problem.
So what I am trying to do, because I am unsure just how many records in my table have this problem, is to do the INSERT
into my parts
table, but every time I get a repeated part_number
value, instead of inserting it into the parts
table, it is instead inserted into a table called parts_duplicates
which won't have the unique restriction for the part_number
column (but still have all the same columns as the parts
table. From here I can analyze my incorrect data points and fix them (hopefully).
My only problem is...I have no idea where to even get started on tackling this. In the question I posted above one of the responses suggested using MERGE
and I am currently in the process of testing that, but I am wondering if there is a better way to go about this.
INSTEAD OF
trigger to accomplish the same, maybe only when duplicates are detected. (Also, personally, I wouldn't useMERGE
unless you have a really good reason.)parts_duplicates
table so I can go through all of them to find out which are good, fix the data, and then import them later. I want to be able to insert everything that doesn't have a duplicate into theparts
table without issue. Would I need to use likeWHERE Count(part_number) > 1
or something for this essentially?