SET IDENTITY_INSERT ON

  • CREATE TABLE dbo.T1l(

    ID INT IDENTITY NOT NULL PRIMARY KEY,

    Name VARCHAR(40) NOT NULL

    )

    GO

    CREATE TABLE dbo.T2(

    ID INT IDENTITY NOT NULL PRIMARY KEY,

    Name VARCHAR(40) NOT NULL

    )

    GO

    INSERT INTO VALUES('B1')

    INSERT INTO VALUES('B2')

    INSERT INTO VALUES('B2')

    INSERT INTO T2 SELECT * FROM T1

    Error:

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

    how to solve this problem ;plz reply

  • Don't use implicit inserts. That's the best solution. Name your columns, in both the insert and the select.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • insert select doesn't work with identities unless you do as GSquared as noted.

    Provide a column list for the insert and the select.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply