By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,678 Members | 1,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,678 IT Pros & Developers. It's quick & easy.

trigger before delete in firebird or mssql

P: n/a
Hi everybody!
I need create trigger in firebird and mssql.
The trigger must do this:

If someone try to delete record in table "mast_trans" and if column "ID"
is equal 145 delete cannot be executed otherwise perform delete.

How can I do this? My books dont have any examples for this :(

Thanks for help, greetings, gregory.
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Tue, 06 Apr 2004 11:46:23 +0200, rozrabiak wrote:
Hi everybody!
I need create trigger in firebird and mssql.
The trigger must do this:

If someone try to delete record in table "mast_trans" and if column "ID"
is equal 145 delete cannot be executed otherwise perform delete.

How can I do this? My books dont have any examples for this :(

Thanks for help, greetings, gregory.


Don't know about firebird. In SQL Server:

CREATE TRIGGER MyTrigger
ON mast_trans
AFTER DELETE
AS
IF EXISTS
(SELECT *
FROM deleted
WHERE ID = 145)
BEGIN
RAISERROR ('Row 145 can't be deleted - transaction aborted.',
16, 1)
ROLLBACK TRANSACTION
END

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #2

P: n/a
rozrabiak <br**@maila.pl> wrote in message news:<c4**********@news.onet.pl>...
Hi everybody!
I need create trigger in firebird and mssql.
The trigger must do this:

If someone try to delete record in table "mast_trans" and if column "ID"
is equal 145 delete cannot be executed otherwise perform delete.

How can I do this? My books dont have any examples for this :(

Thanks for help, greetings, gregory.


Here is one possible way, for MSSQL:

create trigger dbo.TestTrig on dbo.mast_trans
instead of delete
as
begin
if @@rowcount = 0
return
else
delete from dbo.mast_trans
where PrimaryKey in (select PrimaryKey from deleted where id <> 145)
end
Simon
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.