SQL Server Delete

  • Thread starter Thread starter Prabhat
  • Start date Start date
P

Prabhat

Hi All,

Sorry that I am Asking this question in this Group.

I have one doubt in SQL Server, Regarding how DELETE Works?

What is the Actual Thing that SQL Server Do when we delete any record from
the Database Table?
Does it maintain any Falg Internally or actually Delete the Record from
Database?
(Like In FoxPro It store some flag internally so that we can Undelete that
records).

Example, Suppose I have 2 tables of same structure, and I delete one record
from 1st table and put that record into 2nd table then how actually SQL
Server handles that. Does it really move that record or Does it changes the
pointer the record for 2nd table or mark the record for delete in 1st table
and create one record for 2nd table?


Can Any Body Help me in these DOUBTS?

Thanks
Prabhat
 
When it deletes, it's gone.

If you need undelete functionality, wrap the transaction in a transaction,
i.e.
begin tran MyTranOfSomeNameNoteTheNameIsNotRequired
delete from table1 where...
if @@error <> 0
rollback tran
else
commit tran

If you need to remove a row from a table and also insert it in the second,
do the insert first, then the delete.
You can also write a trigger on the "to be deleted from" table and then
query the virtual table called DELETED for the row you just deleted and then
perform an insert to the new table.

But basically, there's no flag and it's not like foxpro.

hth
Eric
 
Back
Top