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)
 is this code right?

Author  Topic 

PatDeV
Posting Yak Master

197 Posts

Posted - 2006-07-06 : 11:35:00
Hi all is this code right for insert and update trigger please check?

Thanks

create trigger [dbo].Emailinsertupdate on [dbo].Email
FOR INSERT,update
AS
if not EXISTS (SELECT c.emailaddress FROM emailtest c join inserted i on c.emailaddress = i.emailaddress)
begin
insert into Emailtest (emailaddress)
select emailaddress from inserted
end
else if EXISTS (SELECT c.emailaddress FROM emailtest c join inserted i on c.emailaddress = i.emailaddress)
begin
update c
set c.emailaddress = i.emailaddress
FROM emailtest c join inserted i on c.emailaddress = i.emailaddress
end

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-07-06 : 12:55:53
Well what is it supposed to do?

Tara Kizer
aka tduggan
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-07-06 : 13:08:21
Well, I see what it's doing and it doesn't make sense to have a trigger to do this when you can just grab the data from the table in the first place...this is overhead for no reason



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-07-06 : 13:12:07
I see what the trigger is doing too, but I'm wondering what it is supposed to do. Without an explanation as to what it is supposed to do, it's hard to say if it is correct.

I agree that this is unnecessary overhead.

Tara Kizer
aka tduggan
Go to Top of Page
   

- Advertisement -