Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 A Delete Trigger that also records who deleted

Author  Topic 

Tariq Changgez
Starting Member

1 Post

Posted - 2004-09-06 : 01:19:57
I want a Delete Trigger that copies the deleted records into an archival table "TS_Deleted". Plus I need two more fields "DeletedDate" and DeletedBy" who's values I set by using GETDATE() and SUSER_SNAME.

My problem is that SQL server does not allow INSERT INTO statement where fields in both tables or not identical, whereas in my case there are two additional fields in the TS_Deleted table.

One solution that comes in my mind is to create these two additional fields in the original table also, but it would be a very unprofessional approach as I will increase the size of the original table unnecessirly which contains one million records.

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2004-09-06 : 02:24:50
I think this miht help you
Insert into TS_Deleted
select *,getdate(),SUSER_SNAME
from <Tablename>
Go to Top of Page
   

- Advertisement -