SQL Server Performance

Add or Update another table

Discussion in 'Getting Started' started by abu_je, Jun 15, 2007.

  1. abu_je New Member

    Hi all,<br />I have two following tables with given columns;<br /><br />Orders Table<br />OrderID<img src='/community/emoticons/emotion-3.gif' alt=':O' />rderDate<img src='/community/emoticons/emotion-41.gif' alt=':Q' />uantity<img src='/community/emoticons/emotion-7.gif' alt=':s' />o on<br /><br />Shipments Table<br />OrderID<img src='/community/emoticons/emotion-3.gif' alt=':O' />rderDate<img src='/community/emoticons/emotion-7.gif' alt=':s' />hipmentQTY<img src='/community/emoticons/emotion-7.gif' alt=':S' />hipmentDate<img src='/community/emoticons/emotion-7.gif' alt=':s' />o on <br /><br />I want to get data in Shipments Table from Orders Table whatever add new or update record in Columns (OrderID, OrderDate).<br /><br />I think Trigger would be Ideal for that but i m unable to do same.<br /><br />Can someone tell me the right way and the code for this.<br /><br />Regards,<br /><br /><br /><br /><br />Regards,
  2. MohammedU New Member

    yes, you can use the trigger...
    Check BOL topic "CREATE TRIGGER" for code...


    MohammedU.
    Moderator
    SQL-Server-Performance.com

    All postings are provided “AS IS” with no warranties for accuracy.
  3. FrankKalis Moderator

  4. abu_je New Member

    Mr. MohammedU
    BOL stand for ? where i can check "Create Trigger"





    Yes Mr. Frank
    you are right OrderDate column shoulb be in only one table when there is PK-FK.

    I have OrderID int [identity]
    column in Orders table that i want to auto add to next in OrderID in Shipments table.







    Regards,
  5. abu_je New Member

    I got the Code for inserting new trigger


    CREATE TRIGGER Insert_Into_Shipment ON [dbo].[Orders]
    FOR INSERT
    AS
    Insert into Shipments (OrderID)
    Select max (OrderID) as OrderID from Orders

    Thanks all of you to helping me



    Regards,
  6. Madhivanan Moderator

    BOL stands for Books On Line which is sql server help file

    Madhivanan

    Failing to plan is Planning to fail

Share This Page