• Welcome, Guest. Please login.
November 28, 2020, 07:01:56 PM


Welcome to the SQLitening support forums!

Copy rows with a new index?

Started by Bern Ertl, January 18, 2013, 12:50:00 PM

Previous topic - Next topic

Bern Ertl

January 18, 2013, 12:50:00 PM Last Edit: January 18, 2013, 12:52:15 PM by Bern Ertl
I've got a table with records that reference another table:

                        DateData NOT NULL,
                        FKey INTEGER NOT NULL REFERENCES AnotherTable( RowID) ON DELETE CASCADE,
                        UNIQUE ( DateData, FKey));

Let's say the table has 3 rows in it with FKey = 4.  I want to copy/insert those 3 rows into the same table, but with a new FKey ( = 7 for example). 

I know I can use a select statement to iterate through the 3 rows explicitly in my code and perform 3 separate inserts to accomplish my goal, but I was wondering if there was any way to achieve the same result with a single SQL statement?

Bern Ertl

I think sometimes just posting the question helps me see the answer.INSERT INTO MyTable (DateData, Data2, FKey) SELECT DateCata, Date2, 7 AS FKey FROM MyTable WHERE FKey=3