'Backup & remove specific records - SQL Server

Is there anyway to:

  1. Remove specific records from the table using a query?

  2. Make a backup from specific records and restore them into another SQL Server instance somewhere else?

You can find the attached in below



Solution 1:[1]

1) If ID is the table's PK (or it is unique) you can just use DELETE FROM TABLE_NAME WHERE ID IN (3, 4). You better check if this will not delete other items (or open a transaction, which is always good).

2) If it is just those 4 records and both databases are on the same server (and both tables have the same schema) you can just do (with the same worries that I have expressed in the answer above)

insert into DESTINATION
select * from SOURCE where id between 73 and 76;

Edit: If you really need to do something more like a row backup you can use the bcp utility:

bcp "select * from SOURCE where id between 73 and 76" queryout "file.dat" -T -c 

bcp DESTINATION in file.dat -T -c

Solution 2:[2]

DELETE FROM ListsItems WHERE ID = (3, 4);

It will remove your record.

Modify it....

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2