TaskCentre v4.5 MS SQL Server Trigger Tl White Paper Dcument Number: PD500-03-02-1_0-WP Orbis Sftware Limited 2010
Table f Cntents COPYRIGHT... 1 TRADEMARKS... 1 INTRODUCTION... 2 Overview... 2 Features... 2 GLOBAL CONFIGURATION... 2 TECHNICAL SUMMARY... 2 Wrking with ther Steps... 2 Dependencies... 2 MS SQL Server Trigger Agent... 3 Objects Cnsumed... 3 Objects Expsed... 3 CONFIGURATION... 3 General... 4 Main... 5 Trigger... 6 Cnfigure... 6 Script... 10 i
Cpyright & Trademarks Cpyright The cpyright in this dcument is wned by Orbis Sftware 2010. All rights reserved. This publicatin may nt, in whle r part, be reprduced, transmitted, transcribed, stred in a retrieval system r translated int any language in any frm r by any means withut the prir written cnsent f Orbis Sftware Limited. Head Office: Orbis Sftware Limited (UK) 2 Nuffield Rad Nuffield Industrial Estate Ple, Drset BH17 0RB United Kingdm Tel: +44 (0) 1202 241124 Fax: +44 (0) 1202 241125 Email: enquiries@rbis-sftware.cm Trademarks Orbis Sftware Ltd wns the registered Trademark TaskCentre. All ther Trademarks used within this dcumentatin are acknwledged as the prperty f their respective wners. The infrmatin prvided in this publicatin may cntain errrs, missins, r typgraphical errrs r may be ut f date. Orbis Sftware may change, delete, r update any published infrmatin at any time and withut prir ntice. The infrmatin published in this dcument is prvided fr infrmatinal purpses nly and is nt binding n Orbis Sftware in any way except t the extent that it is specifically indicated t be s. 1
MS SQL Server Trigger Tl Intrductin Overview The MS SQL Server Trigger Tl is used t create a Task Step that utilises the Micrsft SQL Server trigger functinality t create a trigger n a table f a specified SQL data surce. When a specified data mdificatin is attempted, such as an attempt t add r delete a table rw, the trigger then causes a Task t run. The trigger creates virtual tables fr inserted/updated and deleted rws which may be mapped t Task variables s that the data may be used in ther Steps within the Task. If a Database Query (ODBC) r Database Query (OLEDB) Step is used within the Task t retrieve a recrdset frm the SQL data surce when the data is mdified, then the memry feature may be used in a subsequent Step t memrise all f the data int a Repsitry. Features A Trigger may be activated when any rw is updated, deleted r a new rw inserted. A Trigger may be activated when specified clumns are updated. Values f updated, deleted r new rws in the virtual tables may be mapped t variables fr use in ther Steps within the Task. Glbal Cnfiguratin The MS SQL Server Trigger Tl requires n glbal cnfiguratin. Hwever, SQL Server 2000, 2005 r 2008 data surce is required and the MS SQL Server Trigger Agent must be installed n the same machine as the data surce. Technical Summary Wrking with ther Steps The Schedule Step is independent f any ther Steps used in a Task. Hwever, it accesses parameters that the Task expses thrugh the Task Brwser dialg. Dependencies The prducts, technlgies, prtcls r systems that are required fr the Schedule Step t wrk are listed belw. Micrsft SQL Server 2000, 2005 r 2008 Data Surce MS SQL Server Trigger Agent - The agent must be installed n the SQL Server. 2
MS SQL Server Trigger Tl MS SQL Server Trigger Agent The MS SQL Server Trigger agent is a service that sits between TaskCentre and SQL Server and may be installed nt any SQL Server. It is respnsible fr bth maintaining the Triggers in SQL Server and fr handling the running f a Task nce a Trigger has been fired. When a SQL Server Trigger is fired, the agent service will queue the applicable Task. Objects Cnsumed The Schedule Step cnsumes n bjects expsed by ther Steps. Objects Expsed The bjects that the MS SQL Server Trigger Step expses that can be utilised by ther Steps are listed belw. Variables (Text) - Textual data is mapped t selected Parameter Variables fr use in ther Steps Cnfiguratin A MS SQL Server Trigger Step is cnfigured thrugh the MS SQL Server Trigger dialg which is displayed thrugh the fllwing methds: T create a new Step: In the Task Brwser dialg, select the 'Tls' tab, click n the MS SQL Server Trigger icn under the 'Event' nde and then drag and drp- it nt the Task Plan. The MS SQL Server Trigger dialg will pen and nce created an icn fr the Step will be displayed n the Task Plan. In the Task Brwser dialg, right-click n the Steps nde and select the 'MS SQL Server Trigger' ptin frm the 'New' > 'Event' drp dwn menu. The MS SQL Server Trigger dialg will pen and nce created the Step is displayed under the Steps nde in the Task Brwser. It may then be dragged and drpped nt the Task Plan. Right-click anywhere n the Task Plan in the Design tab f the Task dialg and selected the 'MS SQL Server Trigger Event' ptin frm the 'New' > 'Event' drp dwn menu. The MS SQL Server Trigger dialg will pen and nce created an icn fr the Step will be displayed n the Task Plan. 3
MS SQL Server Trigger Tl T pen an existing Step: On the Task Plan in the Design tab f the Task dialg, duble-click n the MS SQL Server Trigger icn be edited.. The MS SQL Server Trigger dialg will pen t enable the Step details t In the Task Brwser dialg, duble-click n the MS SQL Server Trigger nde displayed under the Steps nde. The MS SQL Server Trigger dialg will pen t enable the Step details t be edited. In the Task Brwser dialg, right-click n the MS SQL Server Trigger nde displayed under the Steps nde and select the 'Edit Step' ptin frm the drp dwn menu. The MS SQL Server Trigger dialg will pen t enable the Step details t be edited. The dialg has three tabbed panes described belw thrugh which an MS SQL Server Trigger Step may be created and cnfigured. General Figure 1. MS SQL Server Trigger General tab. 4
MS SQL Server Trigger Tl The cntents f the General tab (Ref: Figure 1) are as fllws: Name (field) A unique name fr the Step may be manually entered. Descriptin (field) A descriptin fr the Step may be manually entered. Main Figure 2. MS SQL Server Trigger Main tab. The Main tab (Ref: Figure 2) prvides ptins fr cnfiguring the cnnectin t the required database table t be used by the trigger and where mre than ne trigger has been created fr the Task the rder in which it is run. The cntents f the Main tab are as fllws: 'Server' (area) - This area cntains the fllwing fr selecting a server which is hsting the required SQL database: 'Select Server:' (drp dwn list) - Displays a list f all available SQL Servers that have the MS SQL Server Trigger Agent installed fr selectin. 'Select Server Instance:' (drp dwn list) If mre than ne instance f SQL Server is installed n the selected Server, then they are displayed in the list fr selectin. 5
MS SQL Server Trigger Tl 'Credentials' (area) - This area cntains the fllwing fr setting the selected server lgin credentials: 'Lgin Name' (field) - A valid lgin name fr cnnecting t the selected server may be manually entered. 'Passwrd' (field) - A valid passwrd fr the selected lgin name may be manually entered. 'Use Trusted Cnnectin' (check bx) - If this ptin is selected then the currently lgged in Users credentials are used t access the selected server. A different User name may be selected t run the Task if this is required t access the required server / database table thrugh the Impersnatin tab f the Task Optins dialg. 'Select a Table / View' (area) - This are cntains the fllwing fr selecting the required SQL database table r view: 'Create Trigger On:' (field) - Displays the table / clumn names selected frm the SQL database. 'Brwse...' (buttn) - Opens the SQL Server Brwser dialg t enable a SQL database table r view t be selected. 'Trigger Order' (area) - This area prvides the fllwing 'Fire Trigger' ptins fr selectin: 'First' (ptin radi buttn) - If mre than ne trigger has been created fr the Task, selecting this ptin fires this trigger first. 'Last' (ptin radi buttn) - As abve, if mre than ne trigger has been created then selecting this ptin fires this trigger last. 'N rder specified' (ptin radi buttn) - This ptin is selected by default. Trigger The Trigger tab prvides a cmprehensive set f ptins fr cnfiguring the trigger. The dialg has tw tabbed panes listed belw thrugh which a MS SQL Server Trigger may be created and cnfigured. Cnfigure The Cnfigure tab (Ref: Figure 3) prvides cnfiguratin ptins t enable TaskCentre t autmatically create the necessary T-SQL Script fr the trigger. The script created may be viewed by clicking n the Script tab. The Cnfigure tab cntains the fllwing: 'Trigger Type:' (ptin check bxes) - The fllwing ptins are prvided fr selectin: UPDATE - When this trigger type is selected, the trigger is fired when a clumn in the selected table is updated. INSERT - When this trigger type is selected, the trigger is fired when a new rw is added t the table. 6
MS SQL Server Trigger Tl DELETE - When this trigger type is selected, the trigger is fired when an existing rw is deleted frm the table. 'Fire Trigger:' (ptin radi buttns) - The fllwing ptins are prvided fr selectin: AFTER - This is the default trigger ptin which fires the trigger after the table has been updated. INSTEAD OF - When this trigger ptin is selected, the trigger fires and perfrms its task instead f the table being updated. 'Run Task nce fr each Trigger' (ptin radi buttn) - If this ptin is selected then the Task is run nce fr each trigger created fr the Task. Numerus updates may therefre be made t the table but the trigger will nly fire nce. N mapping f results set clumns t Task Parameters is available, but any changes t the database that caused the trigger t fire may be accessed thrugh the TaskCentre memry feature. 'Run Task nce fr each Rw in Results Set in:' (ptin radi buttn) - When the trigger is fired, an 'Inserted' and a 'Deleted' table are prduced cntaining a recrd set depending n the updates made t the riginal table. Selecting this ptin enables yu t select which f the tables is t be used fr running the Task. 'Inserted Table' (ptin radi buttn) - If this table ptin is selected then the Task will run nce fr each rw created in the Inserted table when the SQL trigger was fired. Each rw represents the additin f a new rw in the riginal table and in additin will include any updated rws if the 'UPDATE' trigger type has been previusly selected. 'Deleted Table' (ptin radi buttn) - If this table ptin is selected then the Task will run nce fr each rw created in the Inserted table when the SQL trigger was fired. Each rw represents the editing r deletin f an existing rw in the riginal table. 'Map Clumns t Task Parameters:' (table) - Displays a list f variables created fr the Task. The 'Clumns' clumn cntains a drp dwn list f clumns fr selectin, frm the 'Inserted' and 'Deleted' tables created by the SQL Trigger, t be mapped against the variable. The variable may then be used t expse the selected clumn value t subsequent Steps. 'Only Fire Trigger when a selected Clumn is updated:' (ptin check bx) - Selecting this ptin activates the 'Clumns' table displayed belw it. 'Clumns' (table) - Displays a list f clumns available in the selected database table. A check bx is prvided t the left f each clumn name fr selecting / de-selecting the clumn. The trigger is then fired when any f the selected clumns is updated. 'Filter Table' (ptin check bx) - Selecting this ptin activates the Filter buttn s that it may be selected. 7
MS SQL Server Trigger Tl 'Filter' (buttn) - Clicking n the Filter buttn pens the Selecting the Table Filter Expressin dialg (Ref: Figure 4) t enable a new expressin t be entered. Figure 3. MS SQL Server Trigger Trigger tab - Cnfigure. 8
MS SQL Server Trigger Tl Table Filter Expressin dialg The Table Filter Expressin dialg (Ref: Figure 4) is displayed when the Filter buttn is selected in the Trigger tab f the MS SQL Server Trigger dialg. In the Main tab f the Tl, a SQL database and table are selected and when a trigger fires it creates virtual tables fr inserted/updated and deleted rws in the selected table. Yu can cnfigure the trigger t fire when a specific clumn is updated but thrugh the Table Filter Expressin dialg yu may als create a filter expressin n that clumn value. Fr example, a table is used t stre the value f rders received in a clumn called 'Value'. The Task runs a reprt t list all rders received with a value in excess f 10,000 and then sends it t the Sales Manager. The reprt culd be scheduled t run n a regular basis but the manager requires the reprt t be run each time a new large value rder is received. The fllwing expressin is therefre created fr the trigger 'Inserted.Value > = 10000' t cver ccurrences where the value is equal t r exceeds 10,000. Figure 4. Table Filter Expressin dialg. The dialg cntains the fllwing fr creating a filter: 'Clumns' table - Displays a list f tables/clumns that will be created when the trigger is fired. Inserted and deleted tables/clumns will be created fr each available clumn in the selected table. 'Lgical T-SQL Expressin' text bx - The expressin is manually entered int this area. Any table/clumn listed in the 'Clumns' table may be dragged and drpped int the text bx fr inclusin in the filter expressin. 9
MS SQL Server Trigger Tl Script The Script tab (Ref: Figure 5) is prvided t enable the T-SQL Script fr a trigger t be manually created. When the tab is first selected it will display the T-SQL Script autmatically created fr the trigger thrugh the Cnfigure tab using the default ptins selected in the tab. Selecting the 'Edit' buttn switches the tab t script mde s that the T-SQL Script may be manually edited. Once the script mde has been selected it cannt be reversed and the trigger may nly be edited by updating the T-SQL Script. Figure 5. MS SQL Server Trigger Trigger tab - Script. 10