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
 SQL Server Development (2000)
 Triggers

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-12-18 : 09:14:11
Anne writes "I have two tables Table A AND Table Audit when there is anything done in Table A ie Insert, Delete or Update I want a copy of the record to be sent to Table Audit. In Table A there is only to be the most recent copy, Table Audit should have all copies of the record from the moment it was created to that of it being deleted."

nr
SQLTeam MVY

12543 Posts

Posted - 2001-12-18 : 09:55:51
create trigger x on tbl for insert, update
as
insert tblaudit select *, getdate(), 'U' from inserted
go

create trigger x on tbl for delete
as
insert tblaudit select *, getdate(), 'D' from inserted
go

I have included the date of change and update/delete flag in the audit table.


==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Nazim
A custom title

1408 Posts

Posted - 2001-12-18 : 10:26:20
nr i thought u r on a holiday , enjoying on the beach

-------------------------
"Success is when Preparedness meets Opportunity"
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2001-12-18 : 12:05:29
I am on holiday - well except for yesterday and next Friday.
I'm taking a month to clear up things and to allow friends to prepare for my visits - or find a good excuse to be unnavailable.


==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Nazim
A custom title

1408 Posts

Posted - 2001-12-19 : 01:52:38
aha! thts pretty considerate of u to give friends a choice to decide to meet or skip. Am sure if they use cursors they will avoid u , otherwise u r always welcome anywhere anytime



-------------------------
"Success is when Preparedness meets Opportunity"
Go to Top of Page
   

- Advertisement -