I don't have a server around at the moment to provide you with working code, but all in all you have to create an AFTER INSERT trigger that will insert value inserted.ID (inserted is a system name of result set that holds everything that user inserted into the main table) to other 3 tables.
Feel free to ask if you still have trouble with this.
|||Hi,
keep in mind that the insert trigger will be always fired once per statement not per row. So getting you Id won′t work if you put it in a variable or something like this, a pseudotrigger for you could be something like
CREATE TRIGGER SomeTrigger
ON SOMETable
FOR INSERT
AS
BEGIN
INSERT INTO FirstTable(Columnlist,Othercolumns)
SELECT ID, Othercolumns FROM Inserted
INSERT INTO SecondTable(Columnlist,Othercolumns)
SELECT ID, Othercolumns FROM Inserted
INSERT INTO ThirdTable(Columnlist,Othercolumns)
SELECT ID, Othercolumns FROM Inserted
END
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
sql
No comments:
Post a Comment