MERGE statement to include new column that is an identity column. Don't know how to populate.

  • hxkresl (8/5/2011)


    Well, as I said, those tables are just quick mock ups to illustrate my issue, and do not reflect the naming convention or design practices of the development team where I work. Alas, I could not share the real tables.;-)

    Don't mind Joe, he likes insulting people new to SQL. I can only assume his intention is to drive them away from the forums so that they never learn better.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • I have found this forum to be a big part of my morale support and I agree. Prominent members of the SQL DBA/Dev community are here, helping completely anonymous beginners like me.

    It is because of the non judgemental support, taking me from where I'm at and taking me to the next level, by tiny steps, that has made my growth possible. I know that so many of you do it for no personal gain, just community spirit. It is so unbelievable awesome.

    I believe judgement is good, when given with concrete direction and help, and for the most part I get it here. I am so grateful!

  • hxkresl (8/5/2011)


    ... I am migrating data into an identity column whose values cannot be wholesale reseeded. I have to maintain the associations between existing rows of information in the target table and their identity column values. But, as I am bringing in new data, I also must be able to do inserts on the identity column for the new rows...

    You mean, you want to retain the existing PK's (identity column values) of the source table?

    Have a look at SET IDENTITY_INSERT in Books Online.

    Note also that the MERGE statement is usually preferred for upserts rather than straight inserts.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

Viewing 3 posts - 16 through 17 (of 17 total)

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