Add or Update another table | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Add or Update another table

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,
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.

Ahem, may I ask, why OrderDate is contained in both tables? Is it part of the PK-FK? —
Frank Kalis
Microsoft SQL Server MVP
Contributing Editor, Writer & Forum Moderatorhttp://www.sql-server-performance.com
Webmaster:http://www.insidesql.de
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,
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,
BOL stands for Books On Line which is sql server help file Madhivanan Failing to plan is Planning to fail
]]>