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)
 DELETING A RECORD ABOUT TO BE INSERTED

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-06-28 : 07:39:49
KEVIN writes "I would like to write a trigger that will evaluate a record about to be inserted and if it meets a certain criteria, then delete it from the table it is about to be inserted into.

Example:

The system is about to write record1 into table1 the insert trigger fires and evaluates record1 and determines that this record should not be added to table1 at all.

How would this work?

SQL Server 2000 Windows 2000"

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2004-06-28 : 07:47:25
You just wouldn't run the insert... You can't delete a record that doesn't exist in the first place...
Go to Top of Page

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2004-06-28 : 09:56:37
Do a ROLLBACK TRAN inside the trigger.

OS
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2004-06-28 : 16:51:45
Why not just add the logic to a stored procedure instead of using a trigger? Something like this:

IF NOT EXISTS (
SELECT field
FROM table
WHERE condition
)
BEGIN
INSERT INTO table (
...
-- rest of you insert statement
END
Go to Top of Page
   

- Advertisement -