Insert multiple column data into Another table using Trigger

  • I have 3 tables. I have data in 'already' table.

    during insertion of sample1 table , automatically insert data into 'sampletrig' table . I have used the following query.

    companyname and price will inserted as null value in 'sampletrig' table.

    create table sample1(id int , name varchar(10),age int)

    create table already(id int , pname varchar(20),companyname varchar(20))

    create table sampletrig(id int , pname varchar(10),age int,companyname varchar(20),price int)

    insert into sample1(id,name,age) values(1,'sana',28)

    alter trigger insert_tri on sample1

    after insert as

    begin

    INSERT INTO sampletrig (id, pname,age) SELECT id,name,age FROM inserted

    end

    alter trigger already_trig on already

    after update as

    begin

    DECLARE @companyname VARCHAR(20)

    select @companyname= a.companyname from already a

    update sampletrig set pname = @companyname,price=12

    end

  • Don't start a new thread. Continue with the one you have already. You can find it by hitting my posts middle top of the screen.

    No replies here, follow the thread here.

    http://www.sqlservercentral.com/Forums/Topic1152911-149-1.aspx

Viewing 2 posts - 1 through 2 (of 2 total)

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