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,
This is not the most beautiful solution, but I think it will work for you. First of all, you select your data into a temporary table with a "new" primary key and next you drop the old primary key column from the temp table and use the temp table to insert your "cloned" row.
SELECT
'PrimKey2' AS NewPrimKey,
*
INTO #TMP
FROM PrimKeys
WHERE PrimKey='PrimKey1';
ALTER TABLE #TMP DROP COLUMN PrimKey;
INSERT INTO PrimKeys
SELECT * FROM #TMP;