Quickest way to clone row in SQL

前端 未结 5 1858
鱼传尺愫
鱼传尺愫 2020-12-19 14:44

I want to clone multiple tables\' rows that have a single primary key (PrimKey). What\'s the quickest way to clone a row in SQL Server 2005?

Here\'s an example,

5条回答
  •  清歌不尽
    2020-12-19 15:13

    Not sure what do you mean by "multiple tables' rows that have a single primary key".

    PRIMARY KEY, by definition, is UNIQUE.

    To do your query you need to enumerate all columns:

    INSERT
    INTO    PrimKeys (PrimKey, col1, col2, …)
    SELECT  'PrimKey2' AS PrimKey, col1, col2, …
    FROM    PrimKeys
    WHERE   PrimKey = 'PrimKey1'
    

提交回复
热议问题