Showing posts with label row. Show all posts
Showing posts with label row. Show all posts

Monday, March 12, 2012

Move Row from One table to Another

Hi,
Is there any way i can move a single row to from one table to another [same database].
Basically what i am trying to achive is this. I allow the user to delete a row, but instead of actuall deleting the row, i want to place it into another table [like a recycle bin], which can be restored later.

I know i can simply use insert into statement to add it to the 2nd table and perform the delete statement on table1, but it becomes very tedious becaus there are a lot of fields in my table. I am looking for some other efficient way, if its possible at all.

Any ideas and help is appriciated.

Thanks

DanialOriginally posted by Danial
Hi,
Is there any way i can move a single row to from one table to another [same database].
Basically what i am trying to achive is this. I allow the user to delete a row, but instead of actuall deleting the row, i want to place it into another table [like a recycle bin], which can be restored later.

I know i can simply use insert into statement to add it to the 2nd table and perform the delete statement on table1, but it becomes very tedious becaus there are a lot of fields in my table. I am looking for some other efficient way, if its possible at all.

Any ideas and help is appriciated.

Thanks

Danial

I think the only way to do this to do something like this:

INSERT INTO table2 SELECT * FROM table1 where row = row id.

this will allow you to select all fields without having to type them all. I think this is the most efficent way.|||Thanks, Thats exactly what i was looking for.

Danial

move row data

I have a row that contains invalid information. I have created another row
with the correct data. each row has a sequence number on it. The other two
fields in each row contain binary data. how can I move the binary data from
one row into the incorrect row and maintain the sequence number that is
already involved?--Record the sequence number of the row with incorrect information, and then
--delete it. Assume incorrect your identified by sequence number 12345
DELETE FROM [YourTable] WHERE [SequenceColumn] = 12345
--Copy the information from the row with the corrected values. Assume row
--with corrected values identified by sequence number 67890
SET INDENTITY_INSERT [YourTable] ON
INSERT INTO [YourTable]
([SequenceColumn] , [Other Columns...]) --must list all columns
SELECT 12345, [Other Columns....]
FROM [YourTable]
WHERE [SequenceColumn] = 667890
SET IDENTITY_INSERT [YourTable] OFF
--Delete the row where corrected values where copied from
DELETE FROM [YourTable] WHERE [SequenceColumn] = 67890
"Dgragg" wrote:

> I have a row that contains invalid information. I have created another ro
w
> with the correct data. each row has a sequence number on it. The other t
wo
> fields in each row contain binary data. how can I move the binary data fr
om
> one row into the incorrect row and maintain the sequence number that is
> already involved?