I am trying to create duplicates of certain rows in the same table, with different primary keys. My table has many columns, so I can't specify columns. So far, I have tried copying the rows I'm interested in into a temporary table like:
select * into #Temp from MyTable where col = value
But then in order to insert the values in #Temp back into MyTable, I'd have to
- Enable Identity Insert so that I could insert all rows without specifying each of the numerous columns
- Update each row in #Temp to have new keys, different from those in MyTable
Is there a more elegant solution than how I have proposed to create duplicate rows in a table?
A table as a visual example would be as follows:
MyTable (before)
|---------------------|------------------|------------------|
| Heading 1 | Heading 2 | Heading 2 |
|---------------------|------------------|------------------|
| 1 | 'abc' | 29573 |
|---------------------|------------------|------------------|
| 2 | 'bob' | 57302 |
|---------------------|------------------|------------------|
MyTable (after)
|---------------------|------------------|------------------|
| Heading 1 | Heading 2 | Heading 2 |
|---------------------|------------------|------------------|
| 1 | 'abc' | 29573 |
|---------------------|------------------|------------------|
| 2 | 'bob' | 57302 |
|---------------------|------------------|------------------|
| 3 | 'abc' | 29573 |
|---------------------|------------------|------------------|
| 4 | 'bob' | 57302 |
|---------------------|------------------|------------------|
Unfortunately, the closest answer specified columns which doesn't work for me: How can SQL create duplicate records?