469,167 Members | 1,334 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,167 developers. It's quick & easy.

trigger

I have a table named Contact that has a guid primary key.
After each insert in Contact, I want to insert the primary key
value into another table called accountnumber.

As I understand it, a temporary table called Inserted is created for
triggers,
but I'm not having much luck creating the trigger. Here is what I've
done so far. What am I doing wrong?

CREATE TRIGGER [AccountTrigger] ON [dbo].[Contact]
FOR INSERT
AS

DECLARE @Ref uniqueidentifier

SET @Ref = Inserted.RefID
INSERT AccountNumber (ContactRefID)
VALUES ( @Ref)

Thanks, Rick
Jul 20 '05 #1
1 1486
On 21 Apr 2004 12:15:57 -0700, Rick wrote:
I have a table named Contact that has a guid primary key.
After each insert in Contact, I want to insert the primary key
value into another table called accountnumber.

As I understand it, a temporary table called Inserted is created for
triggers,
but I'm not having much luck creating the trigger. Here is what I've
done so far. What am I doing wrong?

CREATE TRIGGER [AccountTrigger] ON [dbo].[Contact]
FOR INSERT
AS

DECLARE @Ref uniqueidentifier

SET @Ref = Inserted.RefID
INSERT AccountNumber (ContactRefID)
VALUES ( @Ref)

Thanks, Rick


Hi Rick,

Try:

CREATE TRIGGER [AccountTrigger] ON [dbo].[Contact]
FOR INSERT
AS

INSERT AccountNumber (ContactRefID)
SELECT RefID
FROM inserted

Best, Hugo
--

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

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Matik | last post: by
6 posts views Thread by Scott CM | last post: by
9 posts views Thread by Martin | last post: by
reply views Thread by JohnO | last post: by
1 post views Thread by deepdata | last post: by
7 posts views Thread by Shane | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.