please help!!!

  • i would like to know if it is possible to get data from one table and take it to another table..

    for example

    CREATE TABLE Company (dpt_no int unsigned not null auto_increment primary key, dpt_name char(20) not null, salary money not  null)

    ****

    CREATE TABLE sales_dpt (s.no int unsigned not null auto_increment primary key, first_name char(20) not null, last_name char(20) not null, dpt_name char(20) not null, , salary money not null)

    ****

    i only want  the salary column from Company table to go to salary column in the sales_dpt table automatically!!!

     

    what would they trigger or stored procedure be?

     

    thanx in advance

     


    Kindest Regards,

    *4*

  • Please be carefull not to duplicate posts. Leave replies here http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=9&messageid=178989

  • sorry about that i double posting bcoz my internet connection is slow so i refreshed the page again!!! when i noticed i had double posted i tried find where to delete it but failed!!!


    Kindest Regards,

    *4*

  • Do you want to update the salary column in the sales_dpt table to be updated whene you insert / update the company table. If this is your need, then you can write a trigger on insert/update on the company table, so whenever there is any new insert or update on the comapny table, it will reflect in the sales_dpt table.

    However, if you want delete to be taken care of, then also write a delete trigger on the company table.

    --Kishore

     

  • Can you please help me write now?  I am not that good @ triggers!!!

     


    Kindest Regards,

    *4*

  • Do you want triggers for insert/update and delete ?

    Let me know your specs. so that I can help you out.

    --Kishore

  • The table scripts that you have given seems incorrect.

    I have corrected the scripts. Also I have written 2 triggers.

    CREATE TABLE Company

    (dpt_no int not null identity(1,1) primary key,

    dpt_name char(20) not null,

    salary money not  null)

    ****

    CREATE TABLE sales_dpt

    (sno int not null identity(1,1) primary key,

    first_name char(20) not null,

    last_name char(20) not null,

    dpt_name char(20) not null,

    salary money not null)

    ****

    CREATE TRIGGER dbo.tr_company ON dbo.company for insert,update as

    INSERT sales_dpt(dpt_name,salary)

    SELECT dpt_name,salary

    FROM inserted

    ****

    CREATE TRIGGER dbo.tr_company_delete ON dbo.company for delete as

    delete sales_dpt SELECT dpt_name,salary FROM deleted

    Hope this helps.

    --Kishore

  • thanx alot!!!!

    Just wondering!!! Can it work for two more tables? I have three tables. one called "sales", another "hr" and another "it"...

     

     


    Kindest Regards,

    *4*

  • No. You will have separate triggers for separate tables.

    Read Triggers in BOL for more info.

    --Kishore

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

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