Trigger

  • Hello,

    I need help on this.

    trying to build a Trigger but it's not working, the statement is that.

    CREATE TRIGGER [tdlist] ON [dbo].[trunkDList]

    FOR INSERT

    AS

    INSERT INTO TRUNK_LINES

    (trunkid)

    select 'T'+rtrim(RDB) from trunkDlist

    any help will be appreciate

    thanks

  • First everytime you do an Insert you will get all the Records from trunkDList inserted again. I think you are looking for this

    INSERT TRUNK_LINES (trunkid) SELECT 'T'+rtrim(RDB) From inserted

    If that doesn't work can you pleas explain the issue in more detail (Phone company stuff ye-haw).

  • probably want to change the "from trunkdlist" to "from inserted" as Anatares did.

    Steve Jones

    sjones@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/sjones

  • well now I'm getting an error:

    Cannot Insert the NULL into column TIMESTAMP on trunk_lines

    means that , the table I'm trying to update has a timestamp autonumber and do not accept nulls, How I fix that ?

    thanks

    Nelson

  • you should update the table that the trigger is on, referencing the inserted table & joining over the primary key.

    that way you influence the value of the row(s) being inserted, rather than trying to add new ones.

    Edited by - sunshinekid on 12/13/2002 12:14:43 PM

  • well my problem is the both they are not related, so is very hard to update the second table after the first been updated, I lost the variable to locate on the second table, don't know how to fix it.

    thanks

  • my fault for adding to the confusion - didn't spot you were copying rows across to your other table

    don't have any bright ideas for the timestamp - the semantics for timestamp is that you can only insert null into this column & no other value, so it should work.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply