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)
 Coding Help

Author  Topic 

ggarza75
Yak Posting Veteran

50 Posts

Posted - 2009-07-02 : 16:51:27
Need some syntax assistance.
I have a Client Table that is tied in with Primary Contact Table by a foreign key. I have created a stored procedure that when a record with the client’s ID name is called with the SP, it copies the records to another database and deletes it from the Client and Primary Contact tables in Production.

I have a third table called Secondary Contact, which has no key to the Client table. However it does have a key to the Primary Contact table.

How can I have the records in the Secondary Contact table copy and delete when the records of the Primary Contact are copied and deleted?

Thanks. I hope this was clear.

TheSQLGuru
SQL Server MVP

10 Posts

Posted - 2009-07-05 : 10:47:42
Your description was difficult to follow, but I think you need to check out Triggers in Books Online.

Kevin G Boles
TheSQLGuru
Indicium Resources, Inc.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-05 : 13:00:19
As suggested, you need to have a triger like this

CREATE TRIGGER YourTriggerName
ON [Primary Contact]
AFTER DELETE
AS
BEGIN
DELETE s
FROM [Secondary Contact] s
INNER JOIN DELETED d
ON d.keycolumn=s.keycolumn
END
Go to Top of Page

ggarza75
Yak Posting Veteran

50 Posts

Posted - 2009-07-08 : 15:39:21
Thank you very much. This is what I needed.
Go to Top of Page
   

- Advertisement -