Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Is there a way to clone/duplicate a table row in SQL using an existing row PK=0 as default data?

$
0
0

I basically want to take a row of data (Primary Key=0), in a number of tables all with different schema, and call it the "default" and clone it each time as a starting point, simply giving it a new primary key and then offer it up as the default if you do nothing in that table.  I thought first about trying to create some kind of generic class to do that but it seems difficult.  Is there a way to do this in T-SQL / Stored Procedure easily?

So say I have Table1, Table2, Table3, Table4

Table 1
Row1: PKey,Col1,Col2,Col3,Col4

Table 2
Row1: Pkey,ColA,ColB

I want to duplicate it as:

Table 1 (PK + 1)
Row500: 500,Col1,Col2,Col3,Col4

-and

Table2 (PK + 1)
Row 224: 224,ColA,ColB

Table3 something else, Table4 something else, etc.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>