Deleting rows from one table and adding those rows to another table at the same time

Deleting rows from one table and adding those rows to another table at the same time

Post by Domeic » Sun, 16 Jun 2002 03:33:48



Does any one know how to delete rows from one table and add them to
another table at the same time. All using a stored procedure or a trigger.

T.I.A     :)

 
 
 

Deleting rows from one table and adding those rows to another table at the same time

Post by Anith Se » Sun, 16 Jun 2002 03:46:53


If the structure of both tables are the same and you have
no filter criteria for the ROWs to be deleted, you can try
something simple like.

INSERT newTable
SELECT * FROM oldTable
TRUNCATE oldTable

If there is a WHERE clause to filter the data, you may try
something along the lines of

INSERT newTable
SELECT * FROM oldTable
WHERE <criteria>
DELETE FROM oldTable
WHERE <criteria>

If the COLUMNs are different, you have to specify the
COLUMN NAMES in the SELECT clause.

- Anith

Quote:>-----Original Message-----
>Does any one know how to delete rows from one table and
add them to
>another table at the same time. All using a stored

procedure or a trigger.
Quote:

>T.I.A     :)

>.


 
 
 

Deleting rows from one table and adding those rows to another table at the same time

Post by alfre » Sun, 16 Jun 2002 04:42:17


If you wanna use trigger , create it on the table where
you want to delete rows from .

Create  trigger dbo.name for delete as (check syntax)

Insert tab_name_2 select a, b,c from deleted

deleted contains the data deleted from 1st table .
Hope it hhelps

 
 
 

Deleting rows from one table and adding those rows to another table at the same time

Post by Jun Chen[M » Wed, 19 Jun 2002 20:40:57


Hi,

You may create a trigger for delete. In the delete trigger, utilize the
"deleted" table to insert the records to another table. For more
information, please refer to the BOL.

Thanks,
Jun Chen

This posting is provided "AS IS" with no warranties, and confers no rights.