0

I have a table table_A, it has ten rows, id_Row of table from 1 to 10. And I set id_Row is "Identity Increment = true" - Obligate. But now, I want to copy the 7th row => table_A will have 11 rows (and paste into this table_A). I wrote:

INSERT INTO table_A SELECT * FROM  table_A WHERE id_Row = '7'

But I got an error:

An explicit value for the identity column in table 'table_A' can only be specified when a column list is used and IDENTITY_INSERT is ON.

Can someone please let me know how to fix it?

Kate Orlova
  • 3,225
  • 5
  • 11
  • 35
Linh
  • 45
  • 4

1 Answers1

0

You have two option:

1: Before Insert use this script (if id_Row = '7' does not exists in table_A):

SET IDENTITY_INSERT table_A  On

INSERT INTO table_A
SELECT * FROM  table_A WHERE id_Row = '7'

SET IDENTITY_INSERT table_A  Off

2: If id_Row = '7' exists in table_A use columns list explicitly

 INSERT INTO table_A 
 SELECT x,y,z,... FROM  table_A WHERE id_Row = '7'
Hamed Naeemaei
  • 8,052
  • 3
  • 37
  • 46
  • `id_Row = '7'` exists in `table_A` and it has a lot of columns, so i don't want to have to type all the columns out manually. so, how can I do? – Linh Jan 10 '20 at 11:51