Triggering A Stored Procedure With MS SQL Server IntroductionThis article is intended to explain how to initiate a stored procedure using a table and a trigger in Microsoft SQL server. With a stored procedure it is possible to alter several tables at the same time. Background Information
How to Execute a Stored ProcedureThe first step is to create the table which is used to initiate the stored procedure. Therefor create a table with all the columns which are necessary for example as shown in the image below.
This database exists of 3 tables. Table_1 with 2 columns, Table_2 with 2 columns and Table_3 which in this case is used for the Trigger. The trigger will copy the proper columns to the subsequent tables. Table_3 includes all the columns of Table_1 and Table_2. Trigger CodeTo set the trigger, it is possible to configure it manually or open a template. The template method is an easy way to create a trigger. Within the template the required conditions and actions still need to be defined. The trigger which will be created with the query above is named ‘Table_3_to_2&1’ and will be activated on any change on Table_3. When the trigger-code is done, execute the query in order to add the trigger to Table_3. As an example the following Insert instruction is send: This will trigger the stored procedure in Table_3 and this will pass the data to Table_1 and Table_2. After creating the trigger and stored procedure in the database server, the stored procedure can be used in combination with a Sysmac Studio project.
If the Trigger is set correctly and the query is handled correct, the tables are (From 1 to 3 in logic order):
ReferenceStored Procedure (http://msdn.microsoft.com/en-us/library/ms190782.aspx) Link: |
Comments | ||
|