I need to duplicate one row changing the PK. The table can be different in each client installation, so I can't just enumerate the columns. I've managed to do the following:
INSERT INTO table SELECT * FROM table WHERE PK='value'
but obviously it fails because I'm trying to duplicate the PK.
Then I tried:
INSERT INTO table SELECT 'newValue' AS PK, * FROM table WHERE PK='value'
It also failed, because the column names didn't match.
I know the PK will always be the first column, but I'm not sure it's of much use.
So... Is this possible? Any idea?
The only solution is to build the query dynamically by querying for its list of columns and excluding identity column (which is why I'm assuming you wish to skip the PK).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With