How to copy a row of any table by changing one column

I need to duplicate one line modifying PK. Each client installation may have a different table, so I cannot just list the columns. I managed to do the following:

INSERT INTO table SELECT * FROM table WHERE PK='value'

but obviously it fails because I'm trying to duplicate a PC.

Then I tried:

INSERT INTO table SELECT 'newValue' AS PK, * FROM table WHERE PK='value'

It also failed because the column names did not match.

I know that a PC will always be the first column, but I'm not sure if it is very useful.

So ... is this possible? Any idea?

+5
source share
2 answers

, , ( , PK).

+7
INSERT INTO table1 (col1_PK, col2 col3) 
SELECT newValue, col2, col3
FROM table1 
WHERE col1_PK = 'Value'
+2

All Articles