Hi - I'm trying to create a trigger that will do the following:
When a new record is inserted into Table A, a trigger will fire off inserting x number of records into Table B from Table C. Table A and Table C can be joined via a common field, so I am able to select the "x" number of records to insert into Table C fairly easily. However, I'm getting stuck on the second part of what I want the trigger to do. When each new record is inserted into Table C, I would like to get the Primary Key field value back from that insert and write it along with the primary key of Table A into another table, Table D. In a SQL Server Stored Procedure, I believe you could use a statement like:
Select @n1 = n1 from inserted a
To retrieve the primary key when inserting a new record. I'm thinking if Caspio has something similar, I can use a Loop to insert each new record into Table C one at a time, reading back the Primary Key each time and then inserting a new record into Table D. Alternatively, I believe SQL has a SCOPE IDENTITY function that also retrieves the PK of the newly inserted record. Anything similar in Caspio?
BTW - I considered having a second, separate trigger in Table C to insert the record into Table D, but that won't work, because sometimes records will be added manually to Table C and in this case, new records should not be created in Table D.
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
Question
JayDub
Hi - I'm trying to create a trigger that will do the following:
When a new record is inserted into Table A, a trigger will fire off inserting x number of records into Table B from Table C. Table A and Table C can be joined via a common field, so I am able to select the "x" number of records to insert into Table C fairly easily. However, I'm getting stuck on the second part of what I want the trigger to do. When each new record is inserted into Table C, I would like to get the Primary Key field value back from that insert and write it along with the primary key of Table A into another table, Table D. In a SQL Server Stored Procedure, I believe you could use a statement like:
Select @n1 = n1 from inserted a
To retrieve the primary key when inserting a new record. I'm thinking if Caspio has something similar, I can use a Loop to insert each new record into Table C one at a time, reading back the Primary Key each time and then inserting a new record into Table D. Alternatively, I believe SQL has a SCOPE IDENTITY function that also retrieves the PK of the newly inserted record. Anything similar in Caspio?
BTW - I considered having a second, separate trigger in Table C to insert the record into Table D, but that won't work, because sometimes records will be added manually to Table C and in this case, new records should not be created in Table D.
Link to comment
Share on other sites
3 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.