Results 1 to 2 of 2

Thread: Help please with Trigger

  1. #1
    Join Date
    Aug 2003
    Location
    Kyrgyzstan
    Posts
    8

    Help please with Trigger

    hi,
    I was trying to do the following, but failed, so I am here.
    Is it possible to read in trigger the inserted values, im this case it is an incremental integer, and to insert that value into another table?

    look at this code please:

    create table id2
    (
    id2ID int identity(1,1) not null
    constraint PK_id2ID
    primary key,
    id2value varchar(20) not null default 'id2 value'
    )
    go
    create table id1
    (
    idxID int not null
    constraint FK_idx
    foreign key references id2(id2ID),
    id1value varchar(20) not null default 'id1 value'
    )
    go
    create view ids as
    select id2.id2value, id1.id1value
    from id2, id1
    go

    create trigger trig_ids on ids
    instead of insert
    as
    insert id2(id2value)
    select id2value from inserted
    insert id1(idxID, id1value)
    select id2.id2ID, id1value from id2, inserted

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •