I have a SQL insert statement like the following:
insert into mytable(ID,Keyindex,KeyValue)
select Id,1,GenreID
from mytable2
Which should populate my table with data like:
id GenreID ColumnB
0006342c-47bc-436a-a23a-3b40360d9a30 16 1
0006342c-47bc-436a-a23a-3b40360d9a30 19 1
00109775-f0f8-463e-8134-f842aac8b5df 12 1
001211e3-9bf8-45ad-8297-7a0a94aaf06e 13 1
0025218a-9624-4f5e-86cc-f1cfe862cd2a 16 1
0025218a-9624-4f5e-86cc-f1cfe862cd2a 11 1
0025218a-9624-4f5e-86cc-f1cfe862cd2a 15 1
The problem is ID,GenreId and ColumnB are primary keys and I am currently inserting a constand value "1" which results in a primary key violation.
How do I insert into the table so that ColumnB gets populated with a value incrementaly if the IDs are the same.
For example:
id GenreID ColumnB
0006342c-47bc-436a-a23a-3b40360d9a30 16 1
0006342c-47bc-436a-a23a-3b40360d9a30 19 2
00109775-f0f8-463e-8134-f842aac8b5df 12 1
001211e3-9bf8-45ad-8297-7a0a94aaf06e 13 1
0025218a-9624-4f5e-86cc-f1cfe862cd2a 16 1
0025218a-9624-4f5e-86cc-f1cfe862cd2a 16 2
0025218a-9624-4f5e-86cc-f1cfe862cd2a 16 3