<?xml version="1.0" encoding="UTF-8" ?>
<!--
  ~ Copyright (c) DbVis Software AB. All Rights Reserved.
  -->

<!DOCTYPE DatabaseProfile SYSTEM "dbvis-defs.dtd">

<DatabaseProfile
        desc="Profile for SQL Server"
        minver="9.5"
        extends="generic">

   <!--
   Changes:
   - Introduced Schemas/Schema levels in the tree
   - Introduced a System Tables node
   - Added support for Linked Servers (https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/distributed-queries-stored-procedures-transact-sql) 
   -->
   
   -->

   <!-- =================================================================== -->
   <!-- Definition of initialization commands                               -->
   <!-- =================================================================== -->

   <InitCommands extends="true">
      <Command id="sqlserver.isLinkedServersSupported">
         <SQL>
            <![CDATA[
select top 1 'true' from sys.servers
            ]]>
         </SQL>
         <Output index="1" name="IS_LINKED_SERVERS_SUPPORTED"/>
         <OnError>
            <If test="#result.getErrorCode() eq 208" context="runtime">
               <Message type="info">
                  The SYS.SERVERS view is not available (probably due to the SQL Server edition not supporting it). DbVisualizer will work fine but Linked Servers will not be displayed
               </Message>
            </If>
            <Else>
               <!--For any other error we end up here. May happen if "top 1" is not supported on the SQL Server edition being used-->
               <Message type="info">
                  Got error when checking if the SYS.SERVERS view exists. DbVisualizer will work fine but Linked Servers will not be displayed
               </Message>
            </Else>
         </OnError>
      </Command>

      <!--
         The following init command will find out the SQL Server edition and put it in SQL_SERVER_EDITION.
         To use it in an <If> condition:

         <If test="#SQL_SERVER_EDITION eq 'Azure'">
            ...
         </If>
      -->
      <Command id="sqlserver.getSQLServerEdition">
         <SQL>
            <![CDATA[
SELECT
   CASE ServerProperty('EngineEdition')
      WHEN 1 THEN 'Personal'
      WHEN 2 THEN 'Standard'
      WHEN 3 THEN 'Enterprise'
      WHEN 4 THEN 'Express'
      WHEN 5 THEN 'Azure'
      ELSE        'Unknown'
   END
            ]]>
         </SQL>
         <Output index="1" name="SQL_SERVER_EDITION"/>
         <OnError>
            <If test="#result.getErrorCode() neq 0" context="runtime">
               <Message type="info">
                  Got error when using function ServerProperty('EngineEdition'). Probably because ServerProperty() is not available. DbVisualizer will work normally assuming we are accessing a standard SQL Server edition
               </Message>
            </If>
         </OnError>
      </Command>
   </InitCommands>

   <!-- =================================================================== -->
   <!-- Definition of the commands -->
   <!-- =================================================================== -->

   <Commands extends="true">

      <Command id="sqlserver.getSchemas">
         <!-- Use the sys.schemas view for SQL Server 2005 and later.  
              Earlier versions do not have this view or the schema
              concept, but user/owner fills the same purpose.
         -->
         <If test="#util.isDatabaseVersionGTE(9)">
            <SQL>
            <![CDATA[
SELECT
    [${catalog}].sys.schemas.name 'TABLE_SCHEM',
    CASE
        WHEN [${catalog}].sys.schemas.name IN('dbo',
                                            'guest',
                                            'INFORMATION_SCHEMA',
                                            'sys',
                                            'db_owner',
                                            'db_accessadmin',
                                            'db_securityadmin',
                                            'db_ddladmin' ,
                                            'db_backupoperator',
                                            'db_datareader',
                                            'db_datawriter',
                                            'db_denydatareader',
                                            'db_denydatawriter')
        THEN NULL
        ELSE '${catalog}'
    END 'TABLE_CATALOG'
FROM
    [${catalog}].sys.schemas
ORDER BY
    1
            ]]>
            </SQL>
         </If>
         <Else>
            <SQL>
            <![CDATA[
SELECT DISTINCT
    user_name (uid) 'TABLE_SCHEM', '${catalog}' 'TABLE_CATALOG'
FROM
    sysobjects
WHERE
    user_name (uid) IS NOT NULL
AND user_name (uid) NOT LIKE '##%##'
ORDER BY
    1
            ]]>
            </SQL>
         </Else>
      </Command>

      <Command id="sqlserver.getSchemaNames">
         <If test="#util.isDatabaseVersionGTE(9)">
            <SQL>
            <![CDATA[
SELECT
    [${catalog}].sys.schemas.name 'TABLE_SCHEM'
FROM
    [${catalog}].sys.schemas
ORDER BY
    1
            ]]>
            </SQL>
         </If>
         <Else>
            <SQL>
            <![CDATA[
SELECT DISTINCT
    user_name (uid) 'TABLE_SCHEMA'
FROM
    sysobjects
WHERE
    user_name (uid) IS NOT NULL
AND user_name (uid) NOT LIKE '##%##'
ORDER BY
    1
            ]]>
            </SQL>
         </Else>
         <!--Must have Filter element here since this command is fetched from code-->
         <Filter index="TABLE_SCHEM" label="Name"/>
      </Command>

      <!--
        The "getTableNamesFor" command is used by Database getTableNamesFor().
        It must return table names for the catalog and schema named by
        the ${table_catalog} and ${table_catalog} variables in the first
        column.
      -->

      <Command id="sqlserver.getTableNamesFor">
         <SQL>
            <![CDATA[
select TABLE_NAME
from INFORMATION_SCHEMA.TABLES
where TABLE_CATALOG = '${table_catalog}' and TABLE_SCHEMA = '${table_schema}'
order by TABLE_NAME
            ]]>
         </SQL>
      </Command>

      <!--
        The "getColumnNamesFor" command is used by Database getColumnNamesFor().
        It must return column names for the catalog, schema and table named by
        the ${table_catalog}, ${table_catalog} and ${table_name} variables in
        the first column.
      -->
      <Command id="sqlserver.getColumnNamesFor">
         <SQL>
            <![CDATA[
select COLUMN_NAME
from INFORMATION_SCHEMA.COLUMNS
where TABLE_CATALOG = '${table_catalog}' and TABLE_SCHEMA = '${table_schema}'
and TABLE_NAME = '${table_name}'
order by COLUMN_NAME
            ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getObjects">
         <If test="#util.isDatabaseVersionGTE(9)">
            <SQL>
               <![CDATA[
select owner = schema_name(schema_id), name, create_date, modify_date
from [${database}].sys.objects where schema_id = schema_id('${schema}') and type in (${type}) order by owner, name
              ]]>
            </SQL>
         </If>
         <Else>
            <SQL>
               <![CDATA[
select owner = user_name(uid), name, crdate "create_date"
from [${database}].dbo.sysobjects where uid = user_id('${schema}') and type in (${type}) order by owner, name
              ]]>
            </SQL>
         </Else>
      </Command>

      <!--
            <Command id="sqlserver.getObjectSource">
               <SQL>
                  <![CDATA[
      select text from [${database}].dbo.syscomments c, [${database}].dbo.sysobjects s
      where s.id = c.id and s.name = '${name}'
                  ]]>
               </SQL>
            </Command>
      -->

      <Command id="sqlserver.getIndexes">
         <If test="#util.isDatabaseVersionGTE(9)">
            <SQL>
               <![CDATA[
select schema_name(o.schema_id) owner, o.name table_name, i.name index_name
from [${database}].sys.objects o join [${database}].sys.indexes i on i.object_id = o.object_id
where i.index_id != 0 
and i.is_primary_key != 1
and i.is_unique_constraint != 1
and i.is_hypothetical != 1
and schema_name(o.schema_id) like '${schema}'
and o.name like '${table}'
order by owner, o.name, i.name
            ]]>
            </SQL>
         </If>
         <Else>
            <SQL>
               <![CDATA[
select user_name(o.uid) owner, o.name table_name, i.name index_name
from [${database}].dbo.sysobjects o join [${database}].dbo.sysindexes i on i.id = o.id
where i.indid between 1 and 254
and objectproperty(o.id, 'IsUserTable') = 1
and indexproperty(o.id, i.name, 'IsStatistics') = 0
and indexproperty(o.id, i.name, 'IsHypothetical') = 0
and i.name not in
  (select o.name from [${database}].dbo.sysobjects o
   where o.parent_obj = i.id
   and objectproperty(o.id, N'isConstraint') = 1.0)
order by owner, o.name, i.name
            ]]>
            </SQL>
         </Else>
      </Command>

      <Command id="sqlserver.getTableIndexes">
         <SQL>
            <![CDATA[
SELECT
    db_name() as 'TABLE_CAT',
    schema_name(t.schema_id) as 'TABLE_SCHEM',
    t.name as 'TABLE_NAME',
    CASE WHEN i.is_unique = 0 THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT) END as 'NON_UNIQUE',
    t.name as 'INDEX_QUALIFIER',
    i.name as 'INDEX_NAME',
    i.type_desc as 'TYPE',
    ic.key_ordinal as 'ORDINAL_POSITION',
    c.name as 'COLUMN_NAME',
    CASE WHEN ic.is_descending_key = 1 THEN 'D' ELSE 'A' END as 'ASC_OR_DESC',
    convert(varchar(100), i.filter_definition) as 'FILTER_CONDITION'
FROM
    sys.tables t
JOIN
    sys.indexes i
ON
    t.object_id = i.object_id
JOIN
    sys.index_columns ic
ON
    t.object_id = ic.object_id
AND i.index_id = ic.index_id
JOIN
    sys.columns c
ON
    t.object_id = c.object_id
AND ic.column_id = c.column_id
WHERE
    t.name = '${name}'
AND schema_name(t.schema_id) = '${owner}'
ORDER BY
    i.name,
    ic.key_ordinal
            ]]>
         </SQL>
      </Command>
      <Command id="sqlserver.getTriggers">
         <If test="#util.isDatabaseVersionGTE(9)">
            <SQL>
               <![CDATA[
SELECT
   schema_name(s1.schema_id) 'trigger_owner',
   s1.name 'trigger_name',
   s3.name 'table_owner',
   s2.name 'table_name',
   s4.is_disabled 'is_disabled',
   s2.create_date 'create_date',
   s2.modify_date 'modify_date'
FROM
   [${database}].sys.objects s1,
   [${database}].sys.objects s2,
   [${database}].sys.schemas s3,
   [${database}].sys.triggers s4
WHERE
   s1.parent_object_id = s2.object_id
   AND s2.schema_id = s3.schema_id
   AND s1.object_id = s4.object_id
   AND s1.type ='TR'
   AND s2.name like '${tableNamePattern}'
   AND s1.schema_id = schema_id('${schema}')
ORDER BY 2;
              ]]>
            </SQL>
         </If>
         <Else>
            <SQL>
               <![CDATA[
SELECT
   'trigger_owner' = user_name(s1.uid),
   s1.name 'trigger_name',
   s3.name 'table_owner',
   s2.name 'table_name'
FROM
   [${database}].dbo.sysobjects s1,
   [${database}].dbo.sysobjects s2,
   [${database}].dbo.sysusers s3
WHERE
   s1.parent_obj = s2.id
   AND s2.uid = s3.uid
   AND s1.type ='TR'
   AND s2.name like '${tableNamePattern}'
   AND s3.name = '${schema}'
ORDER BY 2;
              ]]>
            </SQL>
         </Else>
      </Command>

      <Command id="sqlserver.getTableTriggers">
         <If test="#util.isDatabaseVersionGTE(9)">
            <SQL>
               <![CDATA[
SELECT DISTINCT
   schema_name(s1.schema_id) 'trigger_owner',
   s1.name 'trigger_name',
   s3.name 'table_owner',
   s2.name 'table_name',
   s5.is_disabled 'is_disabled'
FROM
   [${database}].sys.objects s1,
   [${database}].sys.objects s2,
   [${database}].sys.schemas s3,
   [${database}].sys.triggers s5
WHERE
   s1.parent_object_id = s2.object_id
   AND s2.schema_id = s3.schema_id
   AND s1.object_id = s5.object_id
   AND s1.type ='TR'
   AND s3.name = '${owner}'
   AND s2.name = '${name}'
ORDER BY 2;
              ]]>
            </SQL>
         </If>
         <Else>
            <SQL>
               <![CDATA[
SELECT DISTINCT
   'trigger_owner' = user_name(s1.uid),
   s1.name 'trigger_name',
   s3.name 'table_owner',
   s2.name 'table_name'
FROM
   [${database}].dbo.sysobjects s1,
   [${database}].dbo.sysobjects s2,
   [${database}].dbo.sysusers s3
WHERE
   s1.parent_obj = s2.id
   AND s2.uid = s3.uid
   AND s1.type ='TR'
   AND s2.name = '${name}'
   AND s3.name = '${owner}'
ORDER BY 2;
              ]]>
            </SQL>
         </Else>
      </Command>

      <Command id="sqlserver.getSequences">
         <SQL>
            <![CDATA[
SELECT SEQUENCE_CATALOG,
       SEQUENCE_SCHEMA,
       SEQUENCE_NAME,
       DATA_TYPE,
       NUMERIC_PRECISION,
       NUMERIC_PRECISION_RADIX,
       NUMERIC_SCALE,
       convert(BIGINT, START_VALUE) AS START_VALUE,
       convert(BIGINT, MINIMUM_VALUE) AS MINIMUM_VALUE,
       convert(BIGINT, MAXIMUM_VALUE) AS MAXIMUM_VALUE,
       convert(BIGINT, INCREMENT) AS INCREMENT,
       CYCLE_OPTION,
       DECLARED_DATA_TYPE,
       DECLARED_NUMERIC_PRECISION,
       DECLARED_NUMERIC_SCALE
FROM   INFORMATION_SCHEMA.SEQUENCES
WHERE  SEQUENCE_CATALOG = '${database}'
AND    SEQUENCE_SCHEMA  = '${schema}'
ORDER BY SEQUENCE_NAME
            ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getSynonyms">
         <If test="#util.isDatabaseVersionGTE(9)">
            <SQL>
               <![CDATA[
select owner = schema_name(schema_id), name, create_date, modify_date, base_object_name
from [${database}].sys.synonyms where schema_id = schema_id('${schema}') order by name
              ]]>
            </SQL>
         </If>
         <Else>
            <SQL>
               <![CDATA[
select owner = schema_name(schema_id), name, create_date, base_object_name
from [${database}].dbo.synonyms where schema_id = schema_id('${schema}') order by name
              ]]>
            </SQL>
         </Else>
      </Command>

      <Command id="sqlserver.getUsers">
         <SQL>
            <![CDATA[
exec [${database}].dbo.sp_helpuser
            ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getRoles">
         <SQL>
            <![CDATA[
exec [${database}].dbo.sp_helprole
            ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getRoleMembers">
         <SQL>
            <![CDATA[
 exec [${database}].dbo.sp_helprolemember '${name}'
           ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getUserTypes">
         <SQL>
            <![CDATA[
select t.name 'Data Type', p.name 'System Type', b.name 'Creator',
t.allownulls 'Allow Nulls', t.length 'Length', t.prec 'Precision', t.scale 'Scale'
from [${database}].dbo.systypes t, [${database}].dbo.sysusers b, [${database}].dbo.systypes p
where t.uid = b.uid and t.usertype >= 100 and t.type = p.type and p.usertype =
(select min(usertype) from [${database}].dbo.systypes where type = t.type)
            ]]>
         </SQL>
      </Command>

      <!-- ================================================================= -->
      <!-- DBA related commands requiring certain privileges in the database -->
      <!-- ================================================================= -->

      <Command id="sqlserver.getLogins">
         <SQL>
            <![CDATA[
SELECT
    loginname 'Login ID Name',
    dbname 'Default Database',
    language 'Default Language',
    CASE
        WHEN isntname = 1
        THEN 'NT Account'
        ELSE 'SQL Login'
    END 'Account Type',
    CASE
        WHEN isntgroup = 1
        THEN 'Yes'
        ELSE ' '
    END 'Group Account',
    CASE
        WHEN isntuser = 1
        THEN 'Yes'
        ELSE ' '
    END 'User Account',
    CASE
        WHEN sysadmin = 1
        THEN 'X'
        ELSE ' '
    END 'SysAdmin Member',
    CASE
        WHEN securityadmin = 1
        THEN 'X'
        ELSE ' '
    END 'SecurityAdmin Member',
    CASE
        WHEN serveradmin = 1
        THEN 'X'
        ELSE ' '
    END 'ServerAdmin Member',
    CASE
        WHEN setupadmin = 1
        THEN 'X'
        ELSE ' '
    END 'SetupAdmin Member',
    CASE
        WHEN processadmin = 1
        THEN 'X'
        ELSE ' '
    END 'ProcessAdmin Member',
    CASE
        WHEN diskadmin = 1
        THEN 'X'
        ELSE ' '
    END 'DiskAdmin Member',
    CASE
        WHEN dbcreator = 1
        THEN 'X'
        ELSE ' '
    END 'DbCreator Member'
FROM
    master.dbo.syslogins
            ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getLoginDatabases">
         <SQL>
            <![CDATA[
select a.name "Name", sum(c.size / 512) "Size (MB)"
from master.dbo.sysdatabases a, master.dbo.syslogins b, master.dbo.sysusages c
where (a.suid = b.suid) and (b.suid = ${suid}) and a.dbid = c.dbid group by a.name
            ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getLoginRoles">
         <SQL>
            <![CDATA[
select role_name(lr.srid) "Name", lr.status "Status"
from master.dbo.sysloginroles lr, master.dbo.syslogins l
where lr.suid = l.suid AND l.name = '${login}' AND lr.status = 1
            ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getServerRoles">
         <SQL>
            <![CDATA[
exec sp_helpsrvrole
            ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getServerRoleMembers">
         <SQL>
            <![CDATA[
 exec sp_helpsrvrolemember '${name}'
           ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getDevices">
         <SQL>
            <![CDATA[
select * from master.dbo.sysdevices
            ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getDeviceDatabases">
         <SQL>
            <![CDATA[
select a.name "Name", sum(b.size) / 512 "Size (MB)",
  (select l.name from master.dbo.syslogins l where l.suid=a.suid) "Creator"
from master.dbo.sysdatabases a, master.dbo.sysusages b, master.dbo.sysdevices c
where (a.dbid=b.dbid) and (b.vstart <= c.high) and
(b.vstart >= c.low) and (c.name = '${name}') group by a.name
            ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.serverInfo">
         <SQL>
            <![CDATA[
exec sp_server_info
            ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getCaches">
         <SQL>
            <![CDATA[
select a.name, a.status, a.value,
(select b.value from master.dbo.syscurconfigs b where b.config = a.config and b.comment = a.name)
from master.dbo.sysconfigures a where parent = 19 and config = parent order by 2
            ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getProcesses">
         <SQL>
            <![CDATA[
select * from master.dbo.sysprocesses order by 1
            ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getLocks">
         <SQL>
            <![CDATA[
exec sp_lock
            ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getAgentJobs">
         <SQL>
            <![CDATA[
SELECT DISTINCT
     sJOB.name AS JobName
    , sLOGIN.name AS JobOwner
    , sCAT.name AS JobCategory
    , sJOB.description AS JobDescription    
    , CASE sJOB.enabled
        WHEN 1 THEN 'Yes'
        WHEN 0 THEN 'No'
      END AS IsEnabled
    , CASE sJOBH.run_status
        WHEN 0 THEN 'Failed'
        WHEN 1 THEN 'Succeeded'
        WHEN 2 THEN 'Retry'
        WHEN 3 THEN 'Canceled'
        WHEN 4 THEN 'Running' -- In Progress
      END AS LastRunStatus
    , CASE sJOB.notify_level_eventlog
        WHEN 0 THEN 'Never'
        WHEN 1 THEN 'When the job succeeds'
        WHEN 2 THEN 'When the job fails'
        WHEN 3 THEN 'Whenever the job completes'
        ELSE cast ( notify_level_eventlog as VARCHAR)
      END AS NotifyLevelEventlog
   , CASE sJOB.notify_level_email
        WHEN 0 THEN 'Never'
        WHEN 1 THEN 'When the job succeeds'
        WHEN 2 THEN 'When the job fails'
        WHEN 3 THEN 'Whenever the job completes'
        ELSE cast ( notify_level_email as VARCHAR)
      END AS NotifyLevelEmail
  , sOper.name AS OperatorEmail
  , CASE sJOB.notify_level_netsend
        WHEN 0 THEN 'Never'
        WHEN 1 THEN 'When the job succeeds'
        WHEN 2 THEN 'When the job fails'
        WHEN 3 THEN 'Whenever the job completes'
        ELSE cast ( notify_level_netsend as VARCHAR)
      END AS NotifyLevelNetSend
   , sOperNet.name AS OperatorNetSend
   , CASE sJOB.notify_level_page
        WHEN 0 THEN 'Never'
        WHEN 1 THEN 'When the job succeeds'
        WHEN 2 THEN 'When the job fails'
        WHEN 3 THEN 'Whenever the job completes'
        ELSE cast ( notify_level_page as VARCHAR)
      END AS NotifyLevelPage
     , sOperPage.name AS OperatorPager
    , sJOB.date_created AS JobCreatedOn
    , sJOB.date_modified AS JobLastModifiedOn
    , sSVR.name AS OriginatingServerName
    , sJSTP.step_id AS JobStartStepId
    , sJSTP.step_name AS JobStartStepName
    , CASE
        WHEN sSCH.schedule_uid IS NULL THEN 'No'
        ELSE 'Yes'
      END AS IsScheduled
    , CASE sJOB.delete_level
        WHEN 0 THEN 'Never'
        WHEN 1 THEN 'On Success'
        WHEN 2 THEN 'On Failure'
        WHEN 3 THEN 'On Completion'
      END AS JobDeleteLevel
    , notify_level_email
    , notify_level_page
    , notify_level_eventlog
    , notify_level_netsend
    , delete_level
    , sJOB.notify_email_operator_id  
    , sJOB.notify_page_operator_id 
    , sJOB.notify_netsend_operator_id 
    , sCAT.category_id
    , CASE sJOB.enabled
        WHEN 1 THEN ''
        WHEN 0 THEN 'Disabled'
      END AS IsDisabledText
    , sJOB.job_id AS JobID
FROM
    msdb.dbo.sysjobs AS sJOB
    LEFT JOIN msdb.sys.servers AS sSVR
        ON sJOB.originating_server_id = sSVR.server_id
    LEFT JOIN msdb.dbo.syscategories AS sCAT
        ON sJOB.category_id = sCAT.category_id
    LEFT JOIN msdb.dbo.sysjobsteps AS sJSTP
        ON sJOB.job_id = sJSTP.job_id
        AND sJOB.start_step_id = sJSTP.step_id
   LEFT JOIN master.sys.syslogins AS sLOGIN
        ON sJOB.owner_sid = sLOGIN.sid
    LEFT JOIN msdb.dbo.sysjobschedules AS sJOBSCH
        ON sJOB.job_id = sJOBSCH.job_id
    LEFT JOIN msdb.dbo.sysschedules AS sSCH
        ON sJOBSCH.schedule_id = sSCH.schedule_id
    LEFT JOIN msdb.dbo.sysoperators AS sOper
        ON sOper.id = sJOB.notify_email_operator_id
    LEFT JOIN msdb.dbo.sysoperators AS sOperNet
        ON sOperNet.id = sJOB.notify_netsend_operator_id
    LEFT JOIN msdb.dbo.sysoperators AS sOperPage
        ON sOperPage.id = sJOB.notify_page_operator_id 
     LEFT JOIN msdb.dbo.sysjobhistory AS sJH
        ON sJOB.job_id = sJH.job_id   
            LEFT JOIN (
                SELECT 
                    job_id
                    , run_date
                    , run_time
                    , run_status
                    , run_duration
                    , message
                    , ROW_NUMBER() OVER (
                                            PARTITION BY job_id 
                                            ORDER BY run_date DESC, run_time DESC
                      ) AS RowNumber
                FROM msdb.dbo.sysjobhistory
                WHERE step_id = 0
            ) AS sJOBH
        ON sJOB.job_id = sJOBH.job_id
        AND sJOBH.RowNumber = 1        
         ${jobCondition}
ORDER BY JobName
            ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getAgentJobSteps">
         <SQL>
            <![CDATA[
 SELECT
    step_id
  , step_name
  , subsystem
  , command
  , cmdexec_success_code
  , database_name
  , database_user_name
  , CASE on_success_action
        WHEN 1 THEN 'Quit with success'
        WHEN 2 THEN 'Quit with failure'
        WHEN 3 THEN 'Go to next step'
        WHEN 4 THEN 'Go to step on_success_step_id'
        ELSE cast ( on_success_action as VARCHAR)
      END AS onSuccessAction
  , on_success_step_id  
  , CASE on_fail_action
        WHEN 1 THEN 'Quit with success'
        WHEN 2 THEN 'Quit with failure'
        WHEN 3 THEN 'Go to next step'
        WHEN 4 THEN 'Go to step on_success_step_id'
        ELSE cast ( on_fail_action as VARCHAR)
      END AS OnFailAction
  , on_fail_step_id     
  , retry_attempts
  , retry_interval
  , output_file_name
  , CASE flags
      WHEN 0 THEN 'Overwrite output file'
      WHEN 2 THEN 'Append to output file'
      WHEN 4 THEN 'Write Transact-SQL job step output to step history'
      WHEN 8 THEN 'Write log to table (overwrite existing history)'
      WHEN 16 THEN 'Write log to table (append to existing history)'
      WHEN 32 THEN 'Write all output to job history'
      WHEN 64 THEN 'Create a Windows event to use as a signal for the Cmd jobstep to abort'
        ELSE cast ( flags as VARCHAR)
      END AS FileFlags 
   , CASE sJSTEP.last_run_outcome
        WHEN 0 THEN 'Failed'
        WHEN 1 THEN 'Succeeded'
        WHEN 2 THEN 'Retry'
        WHEN 3 THEN 'Canceled'
        WHEN 5 THEN 'Unknown'
        ELSE cast ( last_run_outcome as VARCHAR)
      END AS LastRunOutcome
   , LastRunDate = msdb.dbo.agent_datetime(
       case when sJSTEP.last_run_date = 0 then NULL else sJSTEP.last_run_date end, sJSTEP.last_run_time)
   , last_run_duration
   , last_run_retries
   , os_run_priority
   , sPROX.name AS ProxyName
   , job_id
   , step_uid
   , on_success_action
   , on_fail_action
   , flags
 FROM msdb.dbo.sysjobsteps sJSTEP
   LEFT JOIN msdb.dbo.sysproxies AS sPROX
   ON sJSTEP.proxy_id = sPROX.proxy_id
  ${jobStepCondition} order by sJSTEP.step_id asc
            ]]>
         </SQL>
      </Command>
      <!--    E.g jobStepCondition =  "where job_id = '${job_id}'" -->

      <Command id="sqlserver.getAgentProperties">
         <SQL>
            <![CDATA[EXEC msdb.dbo.sp_get_sqlagent_properties]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getAgentJobSchedules">
         <SQL>
            <![CDATA[
            SELECT 
    msdb.dbo.sysschedules.schedule_id AS ScheduleID
    , schedule_uid AS ScheduleUID
    , name AS ScheduleName
    , CASE enabled
        WHEN 1 THEN 'Yes'
        WHEN 0 THEN 'No'
      END AS IsEnabled
    , CASE 
        WHEN freq_type = 64 THEN 'Start automatically when SQL Server Agent starts'
        WHEN freq_type = 128 THEN 'Start whenever the CPUs become idle'
        WHEN freq_type IN (4,8,16,32) THEN 'Recurring'
        WHEN freq_type = 1 THEN 'One Time'
      END ScheduleType
    , CASE freq_type
        WHEN 1 THEN 'One Time'
        WHEN 4 THEN 'Daily'
        WHEN 8 THEN 'Weekly'
        WHEN 16 THEN 'Monthly'
        WHEN 32 THEN 'Monthly - Relative to Frequency Interval'
        WHEN 64 THEN 'Start automatically when SQL Server Agent starts'
        WHEN 128 THEN 'Start whenever the CPUs become idle'
      END Occurrence
    , CASE freq_type
        WHEN 4 THEN 'Occurs every ' + CAST(freq_interval AS VARCHAR(3)) + ' day(s)'
        WHEN 8 THEN 'Occurs every ' + CAST(freq_recurrence_factor AS VARCHAR(3)) 
                    + ' week(s) on '
                    + CASE WHEN freq_interval & 1 = 1 THEN 'Sunday' ELSE '' END
                    + CASE WHEN freq_interval & 2 = 2 THEN ', Monday' ELSE '' END
                    + CASE WHEN freq_interval & 4 = 4 THEN ', Tuesday' ELSE '' END
                    + CASE WHEN freq_interval & 8 = 8 THEN ', Wednesday' ELSE '' END
                    + CASE WHEN freq_interval & 16 = 16 THEN ', Thursday' ELSE '' END
                    + CASE WHEN freq_interval & 32 = 32 THEN ', Friday' ELSE '' END
                    + CASE WHEN freq_interval & 64 = 64 THEN ', Saturday' ELSE '' END
        WHEN 16 THEN 'Occurs on Day ' + CAST(freq_interval AS VARCHAR(3)) 
                     + ' of every '
                     + CAST(freq_recurrence_factor AS VARCHAR(3)) + ' month(s)'
        WHEN 32 THEN 'Occurs on '
                     + CASE freq_relative_interval
                        WHEN 1 THEN 'First'
                        WHEN 2 THEN 'Second'
                        WHEN 4 THEN 'Third'
                        WHEN 8 THEN 'Fourth'
                        WHEN 16 THEN 'Last'
                       END
                     + ' ' 
                     + CASE freq_interval
                        WHEN 1 THEN 'Sunday'
                        WHEN 2 THEN 'Monday'
                        WHEN 3 THEN 'Tuesday'
                        WHEN 4 THEN 'Wednesday'
                        WHEN 5 THEN 'Thursday'
                        WHEN 6 THEN 'Friday'
                        WHEN 7 THEN 'Saturday'
                        WHEN 8 THEN 'Day'
                        WHEN 9 THEN 'Weekday'
                        WHEN 10 THEN 'Weekend day'
                       END
                     + ' of every ' + CAST(freq_recurrence_factor AS VARCHAR(3)) 
                     + ' month(s)'
      END AS Recurrence
    , CASE freq_subday_type
        WHEN 1 THEN 'Occurs once at ' 
                    + STUFF(
                 STUFF(RIGHT('000000' + CAST(active_start_time AS VARCHAR(6)), 6)
                                , 3, 0, ':')
                            , 6, 0, ':')
        WHEN 2 THEN 'Occurs every ' 
                    + CAST(freq_subday_interval AS VARCHAR(3)) + ' Second(s) between ' 
                    + STUFF(
                   STUFF(RIGHT('000000' + CAST(active_start_time AS VARCHAR(6)), 6)
                                , 3, 0, ':')
                            , 6, 0, ':')
                    + ' & ' 
                    + STUFF(
                    STUFF(RIGHT('000000' + CAST(active_end_time AS VARCHAR(6)), 6)
                                , 3, 0, ':')
                            , 6, 0, ':')
        WHEN 4 THEN 'Occurs every ' 
                    + CAST(freq_subday_interval AS VARCHAR(3)) + ' Minute(s) between ' 
                    + STUFF(
                   STUFF(RIGHT('000000' + CAST(active_start_time AS VARCHAR(6)), 6)
                                , 3, 0, ':')
                            , 6, 0, ':')
                    + ' & ' 
                    + STUFF(
                    STUFF(RIGHT('000000' + CAST(active_end_time AS VARCHAR(6)), 6)
                                , 3, 0, ':')
                            , 6, 0, ':')
        WHEN 8 THEN 'Occurs every ' 
                    + CAST(freq_subday_interval AS VARCHAR(3)) + ' Hour(s) between ' 
                    + STUFF(
                    STUFF(RIGHT('000000' + CAST(active_start_time AS VARCHAR(6)), 6)
                                , 3, 0, ':')
                            , 6, 0, ':')
                    + ' & ' 
                    + STUFF(
                    STUFF(RIGHT('000000' + CAST(active_end_time AS VARCHAR(6)), 6)
                                , 3, 0, ':')
                            , 6, 0, ':')
      END Frequency
    , STUFF(
            STUFF(CAST(active_start_date AS VARCHAR(8)), 5, 0, '-')
                , 8, 0, '-') AS ScheduleUsageStartDate
    , STUFF(
            STUFF(CAST(active_end_date AS VARCHAR(8)), 5, 0, '-')
                , 8, 0, '-') AS ScheduleUsageEndDate
    , date_created AS ScheduleCreatedOn
    , date_modified AS ScheduleLastModifiedOn
    , CASE enabled
        WHEN 1 THEN ''
        WHEN 0 THEN 'Disabled'
      END AS IsDisabledText
FROM msdb.dbo.sysschedules ${condition}
ORDER BY ScheduleName
            ]]>
         </SQL>
      </Command>

      <!-- sqlserver.getAgentJobServers -->
      <Command id="sqlserver.getAgentJobServers">
         <SQL>
            <![CDATA[EXEC msdb.dbo.sp_help_jobserver @job_name = N'${theJobName}', @show_last_run_details=1]]>
         </SQL>
      </Command>

      <!-- sqlserver.getAgentAlerts Same table structure 2016, 2012,2008R2, 2008, 2005 -->
      <Command id="sqlserver.getAgentAlerts">
         <SQL>
            <![CDATA[select 
id
, sAl.name
, sAl.event_source   
, sAl.event_category_id                                      
, sAl.event_id                   
, CASE sAl.enabled
        WHEN 0 THEN 'Disabled'
        WHEN 1 THEN 'Enabled'
      END enabledStatus                              
, sAl.message_id                                                
, sAl.severity
, sAl.delay_between_responses                         
, sJOB.name AS jobName
, sAl.notification_message
, sAl.database_name
, sAl.event_description_keyword
, sAl.occurrence_count
, CountResetDate = msdb.dbo.agent_datetime(
       case when sAl.count_reset_date = 0 then NULL else sAl.count_reset_date end, sAl.count_reset_time)
, CASE include_event_description
        WHEN 0 THEN '-'
        WHEN 1 THEN 'E-mail'
        WHEN 2 THEN 'Pager'
        WHEN 3 THEN 'E-mail, Pager'
        WHEN 4 THEN 'Net send'
        WHEN 5 THEN 'E-mail, Net send'
        WHEN 6 THEN 'Pager, Net send'
        WHEN 7 THEN 'E-mail, Pager, Net send'
        ELSE CAST (include_event_description AS varchar)
      END includeEventDesc 
 , LastResponseDate = msdb.dbo.agent_datetime(
       case when sAl.last_response_date = 0 then NULL else sAl.last_response_date end,sAl.last_response_time)
 , LastOccurrenceDate = msdb.dbo.agent_datetime(
       case when sAl.last_occurrence_date = 0 then NULL else sAl.last_occurrence_date end, sAl.last_occurrence_time)
 , sAl.has_notification 
 , sAl.flags
 , sAl.enabled 
 , sAl.performance_condition     
 , sAL.category_id 
 , sAl.job_id                                                     
       
  from msdb.dbo.sysalerts as sAl 
   LEFT JOIN msdb.dbo.sysjobs AS sJOB
        ON sJOB.job_id = sAl.job_id
        ${condition}]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getAgentAlertOperators">
         <SQL>
            <![CDATA[
SELECT 
  sOP.name
  , CASE notification_method
        WHEN 0 THEN '-'
        WHEN 1 THEN 'E-mail'
        WHEN 2 THEN 'Pager'
        WHEN 3 THEN 'E-mail, Pager'
        WHEN 4 THEN 'Net send'
        WHEN 5 THEN 'E-mail, Net send'
        WHEN 6 THEN 'Pager, Net send'
        WHEN 7 THEN 'E-mail, Pager, Net send'
        ELSE CAST (notification_method AS varchar)
      END notificationMethod 
   , CASE sOP.enabled
        WHEN 0 THEN 'No'
        WHEN 1 THEN 'Yes'
      END isEnabled    
   , sOP.email_address      
   , LastEmailDate = msdb.dbo.agent_datetime(
       case when sOP.last_email_date = 0 then NULL else sOP.last_email_date end, sOP.last_email_time ) 
   , sOP.pager_address      
   , LastPagerDate = msdb.dbo.agent_datetime(
       case when sOP.last_pager_date = 0 then NULL else sOP.last_pager_date end, sOP.last_pager_time ) 
   ,  CASE WHEN sOP.pager_days & 1 = 1 THEN 'Sunday' ELSE '' END
                    + CASE WHEN sOP.pager_days & 2 = 2 THEN ', Monday' ELSE '' END
                    + CASE WHEN sOP.pager_days & 4 = 4 THEN ', Tuesday' ELSE '' END
                    + CASE WHEN sOP.pager_days & 8 = 8 THEN ', Wednesday' ELSE '' END
                    + CASE WHEN sOP.pager_days & 16 = 16 THEN ', Thursday' ELSE '' END
                    + CASE WHEN sOP.pager_days & 32 = 32 THEN ', Friday' ELSE '' END
                    + CASE WHEN sOP.pager_days & 64 = 64 THEN ', Saturday' ELSE '' END AS PagerDays
   , sOP.weekday_pager_start_time
   , sOP.weekday_pager_end_time
   , sOP.saturday_pager_start_time
   , sOP.saturday_pager_end_time
   , sOP.sunday_pager_start_time
   , sOP.sunday_pager_end_time
   , sOP.pager_days
FROM msdb.dbo.sysnotifications as sNOT
  LEFT JOIN msdb.dbo.sysoperators AS sOP
  ON sNOT.operator_id = sOP.id 
  ${condition} 
  ORDER by sOP.name
            ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getAgentOperators">
         <SQL>
            <![CDATA[
SELECT 
  sOP.name
   , CASE sOP.enabled
        WHEN 0 THEN 'No'
        WHEN 1 THEN 'Yes'
      END isEnabled    
   , sOP.email_address      
   , LastEmailDate = msdb.dbo.agent_datetime(
       case when sOP.last_email_date = 0 then NULL else sOP.last_email_date end, sOP.last_email_time ) 
   , sOP.pager_address      
   , LastPagerDate = msdb.dbo.agent_datetime(
       case when sOP.last_pager_date = 0 then NULL else sOP.last_pager_date end, sOP.last_pager_time ) 
   ,  CASE WHEN sOP.pager_days & 1 = 1 THEN 'Sunday' ELSE '' END
                    + CASE WHEN sOP.pager_days & 2 = 2 THEN ', Monday' ELSE '' END
                    + CASE WHEN sOP.pager_days & 4 = 4 THEN ', Tuesday' ELSE '' END
                    + CASE WHEN sOP.pager_days & 8 = 8 THEN ', Wednesday' ELSE '' END
                    + CASE WHEN sOP.pager_days & 16 = 16 THEN ', Thursday' ELSE '' END
                    + CASE WHEN sOP.pager_days & 32 = 32 THEN ', Friday' ELSE '' END
                    + CASE WHEN sOP.pager_days & 64 = 64 THEN ', Saturday' ELSE '' END AS PagerDays
   , sOP.weekday_pager_start_time
   , sOP.weekday_pager_end_time
   , sOP.saturday_pager_start_time
   , sOP.saturday_pager_end_time
   , sOP.sunday_pager_start_time
   , sOP.sunday_pager_end_time
   , sOP.pager_days
   , sOP.Id
FROM msdb.dbo.sysoperators AS sOP
  ${condition} 
  ORDER by sOP.name
            ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getAgentOperatorsOld">
         <SQL>
            <![CDATA[exec msdb.dbo.sp_help_operator]]>
         </SQL>
      </Command>

      <!-- The alerts an operator -->
      <Command id="sqlserver.getAgentOperatorAlerts">
         <SQL>
            <![CDATA[
SELECT 
  sOP.name
  ,sAL.Id AS AlertId
  ,sAL.name AS AlertName
 , CASE sAL.enabled
        WHEN 1 THEN 'Yes'
        WHEN 0 THEN 'No'
   END AS IsEnabled
  , CASE notification_method
        WHEN 0 THEN '-'
        WHEN 1 THEN 'E-mail'
        WHEN 2 THEN 'Pager'
        WHEN 3 THEN 'E-mail, Pager'
        WHEN 4 THEN 'Net send'
        WHEN 5 THEN 'E-mail, Net send'
        WHEN 6 THEN 'Pager, Net send'
        WHEN 7 THEN 'E-mail, Pager, Net send'
        ELSE CAST (notification_method AS varchar)
      END NotificationMethod 
   , LastOccurrenceDate = msdb.dbo.agent_datetime(
       case when sAL.last_occurrence_date = 0 then NULL else sAL.last_occurrence_date end, sAL.last_occurrence_time)
   , LastResponseDate = msdb.dbo.agent_datetime(
       case when sAL.last_response_date = 0 then NULL else sAL.last_response_date end, sAL.last_response_time )
   ,sAL.delay_between_responses AS DelayBetweenResponses  
   ,sAL.message_id AS MsgId     
   ,sAL.severity AS Severity  
   ,sAL.notification_message AS NotifMessage  
   , CASE include_event_description
        WHEN 0 THEN '-'
        WHEN 1 THEN 'E-mail'
        WHEN 2 THEN 'Pager'
        WHEN 3 THEN 'E-mail, Pager'
        WHEN 4 THEN 'Net send'
        WHEN 5 THEN 'E-mail, Net send'
        WHEN 6 THEN 'Pager, Net send'
        WHEN 7 THEN 'E-mail, Pager, Net send'
        ELSE CAST (include_event_description AS varchar)
      END IncludeEventDescription 
   ,sAL.database_name AS DatabaseName  
   ,sAL.event_description_keyword AS EventDescriptionKeyword 
   ,sAL.occurrence_count AS OccurrenceCount  
  , CountResetDate = msdb.dbo.agent_datetime(
       case when sAL.count_reset_date = 0 then NULL else sAL.count_reset_date end, sAL.count_reset_time )
   ,sJOB.name AS JobName  
   ,sAL.has_notification AS HasNotification  
   
FROM msdb.dbo.sysnotifications as sNOT
  LEFT JOIN msdb.dbo.sysoperators AS sOP
  ON sNOT.operator_id = sOP.id 
  LEFT JOIN msdb.dbo.sysalerts AS sAL
  ON  sNOT.alert_id = sAL.id
  LEFT JOIN msdb.dbo.sysjobs AS sJOB
  ON sAL.job_id = sJOB.job_id
  WHERE sNOT.operator_id = ${operatorId}
  ORDER by sOP.name]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getAgentJobHistory">
         <SQL>
            <![CDATA[
            SELECT 
    RunTime = msdb.dbo.agent_datetime(
       case when sJHIST.run_date = 0 then NULL else sJHIST.run_date end,sJHIST.run_time )
, sJHIST.step_id
, sJHIST.step_name StepName
, sJHIST.run_duration StepDuration
, sJHIST.retries_attempted Retries
, case sJHIST.run_status when 0 then 'failed'
   when 1 then 'Succeded' 
   when 2 then 'Retry' 
   when 3 then 'Cancelled' 
   when 4 then 'In Progress' 
  end as ExecutionStatus 
, sJHIST.server
, sJHIST.message MessageGenerated

FROM msdb.dbo.sysjobhistory sJHIST INNER JOIN msdb.dbo.sysjobs sJOB
ON sJOB.job_id = sJHIST.job_id
WHERE sJOB.job_id = '${jobId}'
ORDER BY sJHIST.instance_id ASC
            ]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getAgentlatestErrorLog">
         <SQL>
            <![CDATA[EXEC xp_readerrorlog 0, ${logtype}]]>
         </SQL>
      </Command>

      <!--
         Get Extended props examples
          Getting for all props for table  'ATabWithExtProps'
               (NULL, 'schema', 'dbo', 'table', 'ATabWithExtProps', NULL, NULL);
          Getting all props for all columns for table 'ATabWithExtProps'
          (NULL, 'schema', 'dbo', 'table', 'ATabWithExtProps', 'column', NULL);
        -->

      <Command id="sqlserver.getExtendedProp">
         <SQL>
            <![CDATA[SELECT objname as '${objectNameLabel}', name as 'Property', convert(varchar(1000), value) as 'Value'
FROM fn_listextendedproperty (${prop_name}, ${lev0_type}, ${lev0_val}, ${lev1_type}, ${lev1_val}, ${lev2_type}, ${lev2_val});]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getLinkedServers">
         <SQL>
            <![CDATA[SELECT * FROM sys.Servers where is_linked = 1]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getOleDbProviders">
         <SQL>
            <![CDATA[exec master.sys.sp_enum_oledb_providers;]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getLinkedCatalogs">
         <SQL>
            <![CDATA[EXEC sp_catalogs @server_name = N'${linkedServer}';]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getLinkedSchemas">
         <SQL>
         	<!-- 
         	No way to query for schemas, alas we select all tables and filter result on distinct schema name (in second column)
         	See https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-tables-ex-transact-sql?view=sql-server-2017 
         	-->
            <![CDATA[EXEC sp_tables_ex @table_server = N'${linkedServer}', @table_catalog = N'${linkedCatalog}']]>
         </SQL>
         <!-- No way to query for schema, we get distinct schema names from table query  -->
         <ProcessDataSet action="distinct" index="TABLE_SCHEM" />
         <ProcessDataSet action="dropcolumn" index="TABLE_NAME"/>
         <ProcessDataSet action="dropcolumn" index="TABLE_TYPE"/>
         <ProcessDataSet action="dropcolumn" index="REMARKS"/>
         <ProcessDataSet action="sortcolumn" index="TABLE_SCHEM"/>
      </Command>

      <Command id="sqlserver.getLinkedSynonyms">
         <SQL>
            <![CDATA[EXEC sp_tables_ex @table_server = N'${linkedServer}', @table_catalog = N'${linkedCatalog}', @table_schema = N'${linkedSchema}', @table_type = N'SYNONYM';]]>
         </SQL>
      </Command>
      
      <Command id="sqlserver.getLinkedTableData">
         <SQL>
            <![CDATA[SELECT * FROM [${linkedServer}].[${linkedCatalog}].[${linkedSchema}].[${linkedTable}];]]>
         </SQL>
      </Command>
      
      <Command id="sqlserver.getLinkedTables">
         <SQL>
            <![CDATA[EXEC sp_tables_ex @table_server = N'${linkedServer}', @table_catalog = N'${linkedCatalog}', @table_schema = N'${linkedSchema}', @table_type = N'TABLE';]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getLinkedTableColumns">
         <SQL>
            <![CDATA[EXEC sp_columns_ex @table_server = N'${linkedServer}', @table_name = N'${linkedTable}', @table_schema = N'${linkedSchema}', @table_catalog = N'${linkedCatalog}';]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getLinkedTableRowCount">
         <SQL>
            <![CDATA[SELECT COUNT(*) FROM [${linkedServer}].[${linkedCatalog}].[${linkedSchema}].[${linkedTable}];]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getLinkedTablePrimaryKeys">
         <SQL>
            <![CDATA[EXEC sp_primarykeys @table_server = N'${linkedServer}', @table_catalog = N'${linkedCatalog}', @table_schema = N'${linkedSchema}', @table_name = N'${linkedTable}';]]>
         </SQL>
      </Command>
      
      <Command id="sqlserver.getLinkedTableForeignKeys">
         <SQL>
           <![CDATA[EXEC sp_foreignkeys @table_server = N'${linkedServer}', @pktab_name = N'${linkedTable}', @pktab_schema = N'${linkedSchema}', @pktab_catalog = N'${linkedCatalog}';]]>
         </SQL>
	  </Command>
      
       <Command id="sqlserver.getLinkedTableIndexes">
         <SQL>
            <![CDATA[EXEC sp_indexes @table_server = N'${linkedServer}', @table_catalog = N'${linkedCatalog}', @table_schema = N'${linkedSchema}', @table_name = N'${linkedTable}';]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getLinkedIndexes">
         <SQL>
            <![CDATA[EXEC sp_indexes @table_server = N'${linkedServer}', @table_catalog = N'${linkedCatalog}', @table_schema = N'${linkedSchema}';]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getLinkedViews">
         <SQL>
            <![CDATA[EXEC sp_tables_ex @table_server = N'${linkedServer}', @table_catalog = N'${linkedCatalog}', @table_schema = N'${linkedSchema}', @table_type = N'VIEW';]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getLinkedTablePrivileges">
         <SQL>
            <![CDATA[EXEC sp_table_privileges_ex @table_server = N'${linkedServer}', @table_name = N'${linkedTable}', @table_schema = N'${linkedSchema}', @table_catalog = N'${linkedCatalog}';]]>
         </SQL>
      </Command>

<!-- NOT (YET) IMPLEMENTED

      <Command id="sqlserver.getLinkedColumnPrivileges">
         <SQL>
            <![CDATA[EXEC sp_column_privileges_ex @table_server = N'${linkedServer}', @table_name = N'${}', @table_schema = N'${linkedSchema}', @table_catalog = N'${linkedCatalog}', @column_name = N'${linkedColumn}';]]>
         </SQL>
      </Command>
      
      <Command id="sqlserver.getLinkedSystemTables">
         <SQL>
            <![CDATA[EXEC sp_tables_ex @table_server = N'${linkedServer}', @table_catalog = N'${linkedCatalog}', @table_schema = N'${linkedSchema}', @table_type = N'SYSTEM TABLE';]]>
         </SQL>
      </Command>

      <Command id="sqlserver.getLinkedSystemViews">
         <SQL>
            <![CDATA[EXEC sp_tables_ex @table_server = N'${linkedServer}', @table_catalog = N'${linkedCatalog}', @table_schema = N'${linkedSchema}', @table_type = N'SYSTEM VIEW';]]>
         </SQL>
      </Command>
 -->

   </Commands>
 
   <!-- =================================================================== -->
   <!-- Definition of the object actions that are used by the tree and views -->
   <!-- =================================================================== -->

   <ObjectsActionDef extends="false">

      <ActionGroup type="Catalogs">
         <Action id="sqlserver-databases-create" label="Create Database" reload="true" resetcatalogs="true" icon="add">
            <Input label="Database" name="newDatabase" style="text"/>
            <Command>
               <SQL>
                  <![CDATA[
                  create database ${QB}${newDatabase}${QE}
                  ]]>
               </SQL>
            </Command>
            <Confirm>
               Confirm creation of ${newDatabase}?
            </Confirm>
            <Result>
               Database ${newDatabase} created!
            </Result>
         </Action>
      </ActionGroup>

      <ActionGroup type="Catalog">
         <Action id="sqlserver-catalog-rename" label="Rename Database" reload="true" resetcatalogs="true" icon="rename">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="New Database Name" name="newDatabase" style="text"/>
            <Command>
               <SQL>
                  <![CDATA[exec sp_renamedb [${catalog}], ${QB}${newDatabase}${QE}]]>
               </SQL>
            </Command>
            <Confirm>
               Confirm rename of ${catalog} to ${newDatabase}?
            </Confirm>
            <Result>
               Database ${catalog} renamed to ${newDatabase}!
            </Result>
         </Action>

         <Action id="sqlserver-catalog-drop" label="Drop Database" reload="true" resetcatalogs="true" icon="remove">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Command>
               <SQL>
                  <![CDATA[
                  use [master];
                  drop database [${catalog}]
                  ]]>
               </SQL>
            </Command>
            <Confirm>
               Confirm drop of ${catalog}?
            </Confirm>
            <Result>
               Database ${catalog} dropped!
            </Result>
         </Action>
      </ActionGroup>

      <ActionGroup type="Schemas">
         <Action id="sqlserver-schemas-create" label="Create Schema" reload="true" resetschemas="true" icon="add">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="New Schema" name="newSchema" style="text"/>
            <Command>
               <SQL>
                  <![CDATA[
                  use [${catalog}];
                  create schema ${QB}${newSchema}${QE}
                  ]]>
               </SQL>
            </Command>
            <Confirm>
               Confirm creation of ${newSchema}?
            </Confirm>
            <Result>
               Schema ${newSchema} created!
            </Result>
         </Action>
      </ActionGroup>

      <ActionGroup type="Schema">
         <Action id="sqlserver-schema-drop" label="Drop Schema" reload="true" resetschemas="true" icon="remove">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Command>
               <SQL>
                  <![CDATA[
                  use [${catalog}];
                  drop schema [${schema}]
                  ]]>
               </SQL>
            </Command>
            <Confirm>
               Confirm drop of ${schema}?
            </Confirm>
            <Result>
               Schema ${schema} dropped!
            </Result>
         </Action>

         <Action id="sqlserver-schema-export" label="Export Schema"
                 icon="export" reload="false"
                 class="schemaExport"
                 doclink="http://www.dbvis.com/doclink/export-schema"/>
      </ActionGroup>

      <ActionGroup type="Tables">
         <Action id="sqlserver-tables-create-table" label="Create Table"
                 icon="add" reload="true"
                 class="tableCreateOrAlter"
                 classargs="create"
                 doclink="http://www.dbvis.com/doclink/create-table"/>
         <Action id="sqlserver-tables-import-table-data"
                 label="Import Table Data"
                 icon="import"
                 reload="true"
                 class="tableDataImport"
                 doclink="http://www.dbvis.com/doclink/import-table"/>
      </ActionGroup>

      <ActionGroup type="Table">
         <Action id="sqlserver-tables-alter-table" label="Alter Table"
                 icon="edit" reload="true"
                 class="tableCreateOrAlter"
                 classargs="alter"
                 doclink="http://www.dbvis.com/doclink/alter-table"/>

         <Action id="sqlserver-table-rename" label="Rename Table" reload="true" icon="rename">
            <Message>
               <![CDATA[<html>
                 Warning: Changing an object or column name could break existing stored procedures, cached statements or other compiled objects.
               ]]>
            </Message>            
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Table" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Input label="New Table Name" name="newTable" style="text"/>
            <Command>
               <SQL>
                  <![CDATA[exec sp_rename [${schema}.${objectname}], ${QB}${newTable}${QE}]]>
               </SQL>
            </Command>
            <Confirm>
               Confirm rename of ${schema}.${objectname} to ${newTable}?
            </Confirm>
            <Result>
               Table ${schema}.${objectname} renamed to ${newTable}!
            </Result>
         </Action>

         <Action id="sqlserver-table-clear" label="Empty Table" reload="true">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Table" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Input label="Use Command" name="useCommand" style="radio">
               <Values>TRUNCATE|DELETE</Values>
               <Default>TRUNCATE</Default>
            </Input>

            <SetVar name="_command" value="#useCommand.equals('TRUNCATE') ? 'truncate table' : 'delete from'"/>

            <Command>
               <SQL>
                  <![CDATA[
                  ${_command} [${schema}].[${objectname}]
                  ]]>
               </SQL>
            </Command>
            <Confirm>
               Really remove all rows in table ${schema}.${objectname}?
            </Confirm>
            <Result>
               All rows in table ${schema}.${objectname} has been removed!
            </Result>
         </Action>

         <Action id="sqlserver-table-drop" label="Drop Table" reload="true" icon="remove">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Table" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Command>
               <SQL>
                  <![CDATA[
                  drop table [${schema}].[${objectname}]
                  ]]>
               </SQL>
            </Command>
            <Confirm>
               Really drop table ${schema}.${objectname}?
            </Confirm>
            <Result>
               Table ${schema}.${objectname} has been dropped!
            </Result>
         </Action>

         <Action id="sqlserver-table-import-table-data" label="Import Table Data" icon="import"
                 class="tableDataImport"
                 doclink="http://www.dbvis.com/doclink/import-table"/>

         <Action id="sqlserver-table-export" label="Export Table" icon="export"
                 class="tableExport"
                 doclink="http://www.dbvis.com/doclink/export-table"/>

         <ActionGroup label="Extended Properties">

            <Action id="sqlserver-table-extended-props-add" label="Add Extended Property" reload="false">
               <Input label="Database" style="text" editable="false">
                  <Default>${catalog}</Default>
               </Input>
               <Input label="Schema" style="text" editable="false">
                  <Default>${schema}</Default>
               </Input>
               <Input label="Table" style="text" editable="false">
                  <Default>${objectname}</Default>
               </Input>

               <Input label="Property Name" name="name" style="text"/>
               <Input label="Value" name="value" style="text-editor" editable="true">
                  <Arg name="height" value="60"/>
               </Input>

               <Command>
                  <SQL>
                     <![CDATA[
EXEC sp_addextendedproperty 
@name = N'${name}', 
@value = N'${value}',
@level0type = N'Schema', @level0name = N'${schema}',
@level1type = N'Table',  @level1name = N'${objectname}';]]>
                  </SQL>
               </Command>
               <Confirm>
                  <![CDATA[Add extended property "${name}" for table ${objectname}?]]>
               </Confirm>
               <Result>
                  <![CDATA[Propery "${name}" was added for table ${objectname}]]>
               </Result>
            </Action>

            <Action id="sqlserver-table-extended-props-delete" label="Delete Extended Property" reload="false">
               <Input label="Database" style="text" editable="false">
                  <Default>${catalog}</Default>
               </Input>
               <Input label="Schema" style="text" editable="false">
                  <Default>${schema}</Default>
               </Input>
               <Input label="Table" style="text" editable="false">
                  <Default>${objectname}</Default>
               </Input>

               <Input label="Property Name" name="name" style="list">
                  <Values>
                     <Command idref="sqlserver.getExtendedProp">
                        <Input name="objectNameLabel" value="Table Name"/>
                        <Input name="prop_name" value="Null"/>
                        <Input name="lev0_type" value="N'schema'"/>
                        <Input name="lev0_val" value="N'${schema}'"/>
                        <Input name="lev1_type" value="N'table'"/>
                        <Input name="lev1_val" value="N'${objectname}'"/>
                        <Input name="lev2_type" value="Null"/>
                        <Input name="lev2_val" value="Null"/>
                        <ProcessDataSet action="dropcolumn" index="Table Name"/>
                        <ProcessDataSet action="dropcolumn" index="value"/>
                     </Command>
                  </Values>
               </Input>

               <Command>
                  <SQL>
                     <![CDATA[
EXEC sp_dropextendedproperty 
  @name = N'${name}', 
  @level0type = N'Schema', @level0name = N'${schema}',
  @level1type = N'Table',  @level1name = N'${objectname}';]]>
                  </SQL>
               </Command>
               <Confirm>
                  <![CDATA[Drop Extended Property "${name}" for table ${objectname}?]]>
               </Confirm>
               <Result>
                  <![CDATA[Property "${name}" deleted for table ${objectname}]]>
               </Result>
            </Action>

            <Action id="sqlserver-table-extended-props-edit" label="Edit Extended Property" reload="false">
               <Input label="Database" style="text" editable="false">
                  <Default>${catalog}</Default>
               </Input>
               <Input label="Schema" style="text" editable="false">
                  <Default>${schema}</Default>
               </Input>
               <Input label="Table" style="text" editable="false">
                  <Default>${objectname}</Default>
               </Input>

               <Input label="Property Name" name="name" runsetdefaultwhenvaluechanged="value" style="list">
                  <Values>
                     <Command idref="sqlserver.getExtendedProp">
                        <Input name="prop_name" value="Null"/>
                        <Input name="objectNameLabel" value="Table Name"/>
                        <Input name="lev0_type" value="N'schema'"/>
                        <Input name="lev0_val" value="N'${schema}'"/>
                        <Input name="lev1_type" value="N'table'"/>
                        <Input name="lev1_val" value="N'${objectname}'"/>
                        <Input name="lev2_type" value="Null"/>
                        <Input name="lev2_val" value="Null"/>
                        <ProcessDataSet action="dropcolumn" index="Table Name"/>
                        <ProcessDataSet action="dropcolumn" index="value"/>
                     </Command>
                  </Values>
               </Input>

               <Input label="Value" name="value" style="text-editor" editable="true">
                  <Arg name="height" value="60"/>
                  <Default>
                     <Command idref="sqlserver.getExtendedProp">
                        <Input name="objectNameLabel" value="Table Name"/>
                        <Input name="prop_name" value="N'${name}'"/>
                        <Input name="lev0_type" value="N'schema'"/>
                        <Input name="lev0_val" value="N'${schema}'"/>
                        <Input name="lev1_type" value="N'table'"/>
                        <Input name="lev1_val" value="N'${objectname}'"/>
                        <Input name="lev2_type" value="Null"/>
                        <Input name="lev2_val" value="Null"/>
                        <ProcessDataSet action="dropcolumn" index="Table Name"/>
                        <ProcessDataSet action="dropcolumn" index="Property"/>
                     </Command>
                  </Default>
               </Input>

               <Command>
                  <SQL>
                     <![CDATA[EXEC sp_updateextendedproperty
@name = N'${name}', 
@value = N'${value}',
@level0type = N'Schema', @level0name = N'${schema}',
@level1type = N'Table',  @level1name = N'${objectname}';]]>
                  </SQL>
               </Command>
               <Confirm>
                  <![CDATA[Update property "${name}" for table ${objectname}?]]>
               </Confirm>
               <Result>
                  <![CDATA[Property "${name}" was changed for table ${objectname}]]>
               </Result>
            </Action>

         </ActionGroup>
         <Separator/>

         <Action id="sqlserver-table-create-index" label="Create Index" reload="true">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Table" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Input label="Index Name" name="indexname" style="text"/>
            <Input label="Unique" name="unique" style="check">
               <Values>unique</Values>
            </Input>

            <Input label="Columns" style="separator"/>

            <Input name="columns" style="grid">
               <Arg name="output" value='"${columnname}"${_sortorder}'/>
               <Arg name="newline" value=", "/>

               <Input name="columnname" label="Column Name" style="list">
                  <Values column="4">
                     <Command idref="getColumnNamesFor">
                        <Input name="table_catalog" value="${catalog}"/>
                        <Input name="table_schema" value="${schema}"/>
                        <Input name="table_name" value="${objectname}"/>
                     </Command>
                  </Values>
                  <Default>${0}</Default>
               </Input>
               <Input name="sortorder" label="Sort Order" style="radio">
                  <Labels>ASC|DESC|Default</Labels>
                  <Values>ASC|DESC|</Values>
                  <Default>ASC</Default>
               </Input>
               <SetVar name="_sortorder" value='#sortorder.equals("") ? "" : " " + #sortorder'/>
            </Input>

            <SetVar name="_unique" value='#unique.equals("") ? "" : " " + #unique'/>
            <SetVar name="_columns" value='#columns.trim().equals("") ? "" : "(" + #columns + ")"'/>
            <SetVar name="_indexname" value='#indexname.trim().equals("") ? "" : " " + #QB + #indexname + #QE'/>

            <Command>
               <SQL>
                  <![CDATA[create${_unique} index${_indexname} on [${schema}].[${objectname}] ${_columns}]]>
               </SQL>
            </Command>
            <Confirm>
               <![CDATA[Create index "${indexname}"?]]>
            </Confirm>
            <Result>
               <![CDATA[Index "${indexname}" created!]]>
            </Result>
         </Action>

         <Action id="sqlserver-tabletrigger-create" label="Create Trigger" icon="add" reload="true"
                 doclink="http://www.dbvis.com/doclink/create-trigger">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Trigger" name="triggerName" style="text"/>
            <Input label="Trigger Time" name="triggerTime" style="radio">
               <Values>FOR|AFTER|INSTEAD OF</Values>
               <Default>AFTER</Default>
            </Input>
            <Input label="Trigger Event" name="eventDelete" style="check" linebreak="false">
               <Values>DELETE</Values>
               <Labels>DELETE</Labels>
            </Input>
            <Input label="" name="eventInsert" style="check">
               <Values>INSERT</Values>
               <Labels>INSERT</Labels>
               <Default>INSERT</Default>
            </Input>
            <Input label="" name="eventUpdate" style="check" linebreak="true">
               <Values>UPDATE</Values>
               <Labels>UPDATE</Labels>
            </Input>
            <Input label="Table" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Input label="Source" style="separator"/>
            <Input name="source" style="text-editor">
               <Default><![CDATA[
--
--  Insert your own trigger code here
--
    insert into anotherTable (col1, col2) values(val1, val2);]]>
               </Default>
            </Input>

            <SetVar name="_triggerEvent" value='#eventDelete'/>
            <SetVar name="_triggerEvent" value='#_triggerEvent.length() > 0 and #eventInsert.length() > 0 ?
                                                #_triggerEvent + ", " + #eventInsert :
                                                #_triggerEvent + #eventInsert'/>
            <SetVar name="_triggerEvent" value='#_triggerEvent.length() > 0 and #eventUpdate.length() > 0 ?
                                                #_triggerEvent + ", " + #eventUpdate :
                                                #_triggerEvent + #eventUpdate'/>

            <Command exectype="asis">
               <SQL>
                  <![CDATA[
create trigger [${schema}].${QB}${triggerName}${QE}
  on [${schema}].[${objectname}]
  ${triggerTime} ${_triggerEvent}
  as 
begin
${source}
end;
]]>
               </SQL>
            </Command>
            <Result>
               <![CDATA[Trigger <b>${schema}.${triggerName}</b> created.]]>
            </Result>
         </Action>

         <Separator/>

         <Action id="sqlserver-table-script" label="Script Table" icon="scriptObject"
                 class="sqlBuilder"
                 classargs="script-dialog,SELECT,SELECT *,INSERT,UPDATE,DELETE,CREATE,DROP"/>

      </ActionGroup>

      <ActionGroup type="View">
         <Action id="sqlserver-view-drop" label="Drop View" reload="true" icon="remove">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="View" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Command>
               <SQL>
                  <![CDATA[
                  drop view [${schema}].[${objectname}]
                  ]]>
               </SQL>
            </Command>
            <Confirm>
               Really drop view ${schema}.${objectname}?
            </Confirm>
            <Result>
               View ${schema}.${objectname} has been dropped!
            </Result>
         </Action>

         <Action id="sqlserver-view-rename" label="Rename View" reload="true" icon="rename">
            <Message>
               <![CDATA[<html>
                 Warning: Changing an object or column name could break existing stored procedures, cached statements or other compiled objects.
               ]]>
            </Message>            
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="View" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Input label="New View Name" name="newView" style="text"/>
            <Command>
               <SQL><![CDATA[exec sp_rename [${schema}.${objectname}], ${QB}${newView}${QE}]]></SQL>
            </Command>
            <Confirm>
               Confirm rename of ${schema}.${objectname} to ${newView}?
            </Confirm>
            <Result>
               View ${schema}.${objectname} renamed to ${newView}!
            </Result>
         </Action>

         <Action id="sqlserver-view-export" label="Export View" icon="export"
                 class="viewExport"
                 doclink="http://www.dbvis.com/doclink/export-view"/>


         <ActionGroup label="Extended Properties">

            <Action id="sqlserver-view-extended-props-add" label="Add Extended Property" reload="false">
               <Input label="Database" style="text" editable="false">
                  <Default>${catalog}</Default>
               </Input>
               <Input label="Schema" style="text" editable="false">
                  <Default>${schema}</Default>
               </Input>
               <Input label="View" style="text" editable="false">
                  <Default>${objectname}</Default>
               </Input>

               <Input label="Property Name" name="name" style="text"/>
               <Input label="Value" name="value" style="text-editor" editable="true">
                  <Arg name="height" value="60"/>
               </Input>

               <Command>
                  <SQL>
                     <![CDATA[
EXEC sp_addextendedproperty 
@name = N'${name}', 
@value = N'${value}',
@level0type = N'Schema', @level0name = N'${schema}',
@level1type = N'View',  @level1name = N'${objectname}';]]>
                  </SQL>
               </Command>
               <Confirm>
                  <![CDATA[Add extended property "${name}" for view ${objectname}?]]>
               </Confirm>
               <Result>
                  <![CDATA[Propery "${name}" was added for view ${objectname}]]>
               </Result>
            </Action>

            <Action id="sqlserver-view-extended-props-delete" label="Delete Extended Property" reload="false">
               <Input label="Database" style="text" editable="false">
                  <Default>${catalog}</Default>
               </Input>
               <Input label="Schema" style="text" editable="false">
                  <Default>${schema}</Default>
               </Input>
               <Input label="View" style="text" editable="false">
                  <Default>${objectname}</Default>
               </Input>

               <Input label="Property Name" name="name" style="list">
                  <Values>
                     <Command idref="sqlserver.getExtendedProp">
                        <Input name="objectNameLabel" value="Table Name"/>
                        <Input name="prop_name" value="Null"/>
                        <Input name="lev0_type" value="N'schema'"/>
                        <Input name="lev0_val" value="N'${schema}'"/>
                        <Input name="lev1_type" value="N'View'"/>
                        <Input name="lev1_val" value="N'${objectname}'"/>
                        <Input name="lev2_type" value="Null"/>
                        <Input name="lev2_val" value="Null"/>
                        <ProcessDataSet action="dropcolumn" index="Table Name"/>
                        <ProcessDataSet action="dropcolumn" index="value"/>
                     </Command>
                  </Values>
               </Input>

               <Command>
                  <SQL>
                     <![CDATA[
EXEC sp_dropextendedproperty 
  @name = N'${name}', 
  @level0type = N'Schema', @level0name = N'${schema}',
  @level1type = N'View',  @level1name = N'${objectname}';]]>
                  </SQL>
               </Command>
               <Confirm>
                  <![CDATA[Drop Extended Property "${name}" for view ${objectname}?]]>
               </Confirm>
               <Result>
                  <![CDATA[Property "${name}" deleted for view ${objectname}]]>
               </Result>
            </Action>

            <Action id="sqlserver-view-extended-props-edit" label="Edit Extended Property" reload="false">
               <Input label="Database" style="text" editable="false">
                  <Default>${catalog}</Default>
               </Input>
               <Input label="Schema" style="text" editable="false">
                  <Default>${schema}</Default>
               </Input>
               <Input label="View" style="text" editable="false">
                  <Default>${objectname}</Default>
               </Input>

               <Input label="Property Name" name="name" runsetdefaultwhenvaluechanged="value" style="list">
                  <Values>
                     <Command idref="sqlserver.getExtendedProp">
                        <Input name="prop_name" value="Null"/>
                        <Input name="objectNameLabel" value="Table Name"/>
                        <Input name="lev0_type" value="N'schema'"/>
                        <Input name="lev0_val" value="N'${schema}'"/>
                        <Input name="lev1_type" value="N'View'"/>
                        <Input name="lev1_val" value="N'${objectname}'"/>
                        <Input name="lev2_type" value="Null"/>
                        <Input name="lev2_val" value="Null"/>
                        <ProcessDataSet action="dropcolumn" index="Table Name"/>
                        <ProcessDataSet action="dropcolumn" index="value"/>
                     </Command>
                  </Values>
               </Input>

               <Input label="Value" name="value" style="text-editor" editable="true">
                  <Arg name="height" value="60"/>
                  <Default>
                     <Command idref="sqlserver.getExtendedProp">
                        <Input name="objectNameLabel" value="Table Name"/>
                        <Input name="prop_name" value="N'${name}'"/>
                        <Input name="lev0_type" value="N'schema'"/>
                        <Input name="lev0_val" value="N'${schema}'"/>
                        <Input name="lev1_type" value="N'View'"/>
                        <Input name="lev1_val" value="N'${objectname}'"/>
                        <Input name="lev2_type" value="Null"/>
                        <Input name="lev2_val" value="Null"/>
                        <ProcessDataSet action="dropcolumn" index="Table Name"/>
                        <ProcessDataSet action="dropcolumn" index="Property"/>
                     </Command>
                  </Default>
               </Input>

               <Command>
                  <SQL>
                     <![CDATA[EXEC sp_updateextendedproperty
@name = N'${name}', 
@value = N'${value}',
@level0type = N'Schema', @level0name = N'${schema}',
@level1type = N'View',  @level1name = N'${objectname}';]]>
                  </SQL>
               </Command>
               <Confirm>
                  <![CDATA[Update property "${name}" for view ${objectname}?]]>
               </Confirm>
               <Result>
                  <![CDATA[Property "${name}" was changed for view ${objectname}]]>
               </Result>
            </Action>

         </ActionGroup>

         <Separator/>

         <Action id="sqlserver-viewtrigger-create" label="Create Trigger" icon="add" reload="true">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Trigger" name="triggerName" style="text"/>

            <Input label="Trigger Event" name="eventDelete" style="check" linebreak="false">
               <Values>DELETE</Values>
               <Labels>DELETE</Labels>
            </Input>
            <Input label="" name="eventInsert" style="check">
               <Values>INSERT</Values>
               <Labels>INSERT</Labels>
               <Default>INSERT</Default>
            </Input>
            <Input label="" name="eventUpdate" style="check" linebreak="true">
               <Values>UPDATE</Values>
               <Labels>UPDATE</Labels>
            </Input>
            <Input label="View" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Input label="Source" style="separator"/>
            <Input name="source" style="text-editor">
               <Default><![CDATA[
--
--  Insert your own trigger code here
--
    insert into anotherTable (col1, col2) values(val1, val2);]]>
               </Default>
            </Input>

            <SetVar name="_triggerEvent" value='#eventDelete'/>
            <SetVar name="_triggerEvent" value='#_triggerEvent.length() > 0 and #eventInsert.length() > 0 ?
                                                #_triggerEvent + ", " + #eventInsert :
                                                #_triggerEvent + #eventInsert'/>
            <SetVar name="_triggerEvent" value='#_triggerEvent.length() > 0 and #eventUpdate.length() > 0 ?
                                                #_triggerEvent + ", " + #eventUpdate :
                                                #_triggerEvent + #eventUpdate'/>

            <Command exectype="asis">
               <SQL>
                  <![CDATA[
create trigger [${schema}].${QB}${triggerName}${QE}
  on [${schema}].[${objectname}]
  INSTEAD OF ${_triggerEvent}
  as 
begin
${source}
end;
]]>
               </SQL>
            </Command>
            <Result>
               <![CDATA[Trigger <b>${schema}.${triggerName}</b> created.]]>
            </Result>
         </Action>

         <Separator/>

         <Action id="sqlserver-view-script" label="Script View" icon="scriptObject"
                 class="sqlBuilder"
                 classargs="script-dialog,SELECT,SELECT *,INSERT,UPDATE,DELETE,CREATE,DROP"/>

      </ActionGroup>

      <ActionGroup type="Index">
         <Action id="sqlserver-index-drop" label="Drop Index" reload="true" icon="remove">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Table" style="text" editable="false">
               <Default>${sqlserver.getIndexes.TABLE_NAME}</Default>
            </Input>
            <Input label="Index" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Command>
               <SQL>
                  <![CDATA[drop index [${objectname}] on [${schema}].[${sqlserver.getIndexes.TABLE_NAME}]]]>
               </SQL>
            </Command>
            <Confirm>
               Really drop index ${objectname} for table
               ${sqlserver.getIndexes.TABLE_NAME}?
            </Confirm>
            <Result>
               Index ${sqlserver.getIndexes.TABLE_NAME}.${objectname} dropped!
            </Result>
         </Action>

         <Action id="sqlserver-index-rename" label="Rename Index" reload="true" icon="rename">
            <Message>
               <![CDATA[<html>
                 Warning: Changing an object or column name could break existing stored procedures, cached statements or other compiled objects.
               ]]>
            </Message>            
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Table" style="text" editable="false">
               <Default>${sqlserver.getIndexes.TABLE_NAME}</Default>
            </Input>
            <Input label="Index" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Input label="New Index Name" name="newIndex" style="text"/>
            <Command>
               <SQL>
                  <![CDATA[exec sp_rename [${schema}.${sqlserver.getIndexes.TABLE_NAME}.${objectname}], ${QB}${newIndex}${QE}]]>
               </SQL>
            </Command>
            <Confirm>
               Confirm rename of index ${objectname} to ${newIndex}?
            </Confirm>
            <Result>
               Index ${objectname} for table ${sqlserver.getIndexes.TABLE_NAME} renamed to ${newIndex}!
            </Result>
         </Action>

         <If test="#util.isDatabaseVersionGTE(9)">
            <Action id="sqlserver-index-rebuild" label="Rebuild Index">
               <Input label="Database" style="text" editable="false">
                  <Default>${catalog}</Default>
               </Input>
               <Input label="Schema" style="text" editable="false">
                  <Default>${sqlserver.getIndexes.OWNER}</Default>
               </Input>
               <Input label="Index" style="text" editable="false">
                  <Default>${objectname}</Default>
               </Input>
               <Command>
                  <SQL>
                     <![CDATA[alter index [${objectname}] on [${sqlserver.getIndexes.OWNER}].[${sqlserver.getIndexes.TABLE_NAME}] rebuild]]>
                  </SQL>
               </Command>
               <Confirm>
                  Confirm rebuild of index
                  ${sqlserver.getIndexes.OWNER}.${objectname}?
               </Confirm>
               <Result>Index ${sqlserver.getIndexes.OWNER}.${objectname}
                  rebuilt!
               </Result>
            </Action>
         </If>
      </ActionGroup>

      <ActionGroup type="Trigger">
         <Action id="sqlserver-trigger-drop" label="Drop Trigger" reload="true" icon="remove">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Trigger" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Command>
               <SQL>
                  <![CDATA[
                  drop trigger [${schema}].[${objectname}]
                  ]]>
               </SQL>
            </Command>
            <Confirm>
               Really drop trigger ${schema}.${objectname}?
            </Confirm>
            <Result>
               Trigger ${schema}.${objectname} dropped!
            </Result>
         </Action>

         <Action id="sqlserver-trigger-rename" label="Rename Trigger" reload="true" icon="rename">
            <Message>
               <![CDATA[<html>
                 Warning: Changing an object or column name could break existing stored procedures, cached statements or other compiled objects.
               ]]>
            </Message>            
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Trigger" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Input label="New Trigger Name" name="newTrigger" style="text"/>
            <Command>
               <SQL>
                  <![CDATA[exec sp_rename [${objectname}], ${QB}${newTrigger}${QE}]]></SQL>
            </Command>
            <Confirm>
               Confirm rename of trigger ${schema}.${objectname} to
               ${newTrigger}?
            </Confirm>
            <Result>
               Trigger ${schema}.${objectname} renamed to ${newTrigger}!
            </Result>
         </Action>

         <Action id="sqlserver-trigger-enable" label="Enable Trigger" reload="true" icon="enable">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Trigger" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Command>
               <SQL>
                  <![CDATA[enable trigger [${schema}].[${objectname}] on [${table_owner}].[${table_name}]]]>
               </SQL>
            </Command>
            <Confirm>
               Really enable trigger ${schema}.${objectname}?
            </Confirm>
            <Result>
               Trigger ${schema}.${objectname} enabled!
            </Result>
         </Action>

         <Action id="sqlserver-trigger-disable" label="Disable Trigger" reload="true" icon="disable">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Trigger" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Command>
               <SQL>
                  <![CDATA[disable trigger [${schema}].[${objectname}] on [${table_owner}].[${table_name}]]]>
               </SQL>
            </Command>
            <Confirm>
               Really disable trigger ${schema}.${objectname}?
            </Confirm>
            <Result>
               Trigger ${schema}.${objectname} disabled!
            </Result>
         </Action>

         <Action id="sqlserver-trigger-export" label="Export Trigger" icon="export"
                 class="triggerExport"
                 doclink="http://www.dbvis.com/doclink/export-code-object"/>
      </ActionGroup>

      <ActionGroup type="Column">
         <Action id="sqlserver-column-rename" label="Rename Column" reload="true" icon="rename">
            <Message>
               <![CDATA[<html>
                 Warning: Changing an object or column name could break existing stored procedures, cached statements or other compiled objects.
               ]]>
            </Message>            
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Table" style="text" editable="false">
               <Default>${theTableName}</Default>
            </Input>
            <Input label="Column" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Input label="New Column Name" name="newColumn" style="text"/>
            <Command>
               <SQL><![CDATA[exec sp_rename [${schema}.${theTableName}.${objectname}], ${QB}${newColumn}${QE}, 'COLUMN']]></SQL>
            </Command>
            <Confirm>
               Confirm rename of column ${objectname} to ${newColumn}?
            </Confirm>
            <Result>
               Column ${objectname} renamed to ${newColumn}!
            </Result>
         </Action>

         <!-- Extended Props for columns -->
         <ActionGroup label="Extended Properties">

            <Action id="sqlserver-column-extended-props-add" label="Add Extended Property" reload="false">
               <Input label="Database" style="text" editable="false">
                  <Default>${catalog}</Default>
               </Input>
               <Input label="Schema" style="text" editable="false">
                  <Default>${schema}</Default>
               </Input>
               <Input label="Table" style="text" editable="false">
                  <Default>${theTableName}</Default>
               </Input>
               <Input label="Column" style="text" editable="false">
                  <Default>${objectname}</Default>
               </Input>
               <Input label="Property Name" name="name" style="text"/>
               <Input label="Value" name="value" style="text-editor" editable="true">
                  <Arg name="height" value="60"/>
               </Input>

               <Command>
                  <SQL>
                     <![CDATA[
EXEC sp_addextendedproperty 
@name = N'${name}', 
@value = N'${value}',
@level0type = N'Schema', @level0name = N'${schema}',
@level1type = ${extPropType1},  @level1name = N'${theTableName}',
@level2type = N'Column',  @level2name = N'${objectname}';]]>
                  </SQL>
               </Command>
               <Confirm>
                  <![CDATA[Add extended property "${name}" for column ${objectname}?]]>
               </Confirm>
               <Result>
                  <![CDATA[Propery "${name}" was added for column ${objectname}]]>
               </Result>
            </Action>

            <Action id="sqlserver-column-extended-props-delete" label="Delete Extended Property" reload="false">
               <Input label="Database" style="text" editable="false">
                  <Default>${catalog}</Default>
               </Input>
               <Input label="Schema" style="text" editable="false">
                  <Default>${schema}</Default>
               </Input>
               <Input label="Table" style="text" editable="false">
                  <Default>${theTableName}</Default>
               </Input>
               <Input label="Column" style="text" editable="false">
                  <Default>${objectname}</Default>
               </Input>

               <Input label="Property Name" name="name" style="list">
                  <Values>
                     <Command idref="sqlserver.getExtendedProp">
                        <Input name="objectNameLabel" value="Column Name"/>
                        <Input name="prop_name" value="Null"/>
                        <Input name="lev0_type" value="N'schema'"/>
                        <Input name="lev0_val" value="N'${schema}'"/>
                        <Input name="lev1_type" value="${extPropType1}"/>
                        <Input name="lev1_val" value="N'${theTableName}'"/>
                        <Input name="lev2_type" value="N'Column'"/>
                        <Input name="lev2_val" value="N'${objectname}'"/>
                        <ProcessDataSet action="dropcolumn" index="Column Name"/>
                        <ProcessDataSet action="dropcolumn" index="value"/>
                     </Command>
                  </Values>
               </Input>

               <Command>
                  <SQL>
                     <![CDATA[
EXEC sp_dropextendedproperty 
  @name = N'${name}', 
  @level0type = N'Schema', @level0name = N'${schema}',
  @level1type = ${extPropType1},  @level1name = N'${theTableName}',
  @level2type = N'Column',  @level2name = N'${objectname}';]]>
                  </SQL>
               </Command>
               <Confirm>
                  <![CDATA[Drop Extended Property "${name}" for column ${objectname}?]]>
               </Confirm>
               <Result>
                  <![CDATA[Property "${name}" deleted for column ${objectname}]]>
               </Result>
            </Action>

            <Action id="sqlserver-column-extended-props-edit" label="Edit Extended Property" reload="false">
               <Input label="Database" style="text" editable="false">
                  <Default>${catalog}</Default>
               </Input>
               <Input label="Schema" style="text" editable="false">
                  <Default>${schema}</Default>
               </Input>
               <Input label="Table" style="text" editable="false">
                  <Default>${theTableName}</Default>
               </Input>
               <Input label="Column" style="text" editable="false">
                  <Default>${objectname}</Default>
               </Input>

               <Input label="Property Name" name="name" runsetdefaultwhenvaluechanged="value" style="list">
                  <Values>
                     <Command idref="sqlserver.getExtendedProp">
                        <Input name="prop_name" value="Null"/>
                        <Input name="objectNameLabel" value="Column Name"/>
                        <Input name="lev0_type" value="N'schema'"/>
                        <Input name="lev0_val" value="N'${schema}'"/>
                        <Input name="lev1_type" value="${extPropType1}"/>
                        <Input name="lev1_val" value="N'${theTableName}'"/>
                        <Input name="lev2_type" value="N'Column'"/>
                        <Input name="lev2_val" value="N'${objectname}'"/>
                        <ProcessDataSet action="dropcolumn" index="Column Name"/>
                        <ProcessDataSet action="dropcolumn" index="value"/>
                     </Command>
                  </Values>
               </Input>

               <Input label="Value" name="value" style="text-editor" editable="true">
                  <Arg name="height" value="60"/>
                  <Default>
                     <Command idref="sqlserver.getExtendedProp">
                        <Input name="objectNameLabel" value="Column Name"/>
                        <Input name="prop_name" value="N'${name}'"/>
                        <Input name="lev0_type" value="N'schema'"/>
                        <Input name="lev0_val" value="N'${schema}'"/>
                        <Input name="lev1_type" value="${extPropType1}"/>
                        <Input name="lev1_val" value="N'${theTableName}'"/>
                        <Input name="lev2_type" value="N'Column'"/>
                        <Input name="lev2_val" value="N'${objectname}'"/>
                        <ProcessDataSet action="dropcolumn" index="Column Name"/>
                        <ProcessDataSet action="dropcolumn" index="Property"/>
                     </Command>
                  </Default>
               </Input>

               <Command>
                  <SQL>
                     <![CDATA[EXEC sp_updateextendedproperty
@name = N'${name}', 
@value = N'${value}',
@level0type = N'Schema', @level0name = N'${schema}',
@level1type = ${extPropType1},  @level1name = N'${theTableName}', 
@level2type = N'Column',  @level2name = N'${objectname}';]]>
                  </SQL>
               </Command>
               <Confirm>
                  <![CDATA[Update property "${name}" for column ${objectname}?]]>
               </Confirm>
               <Result>
                  <![CDATA[Property "${name}" was changed for column ${objectname}]]>
               </Result>
            </Action>

         </ActionGroup>

         <!-- End Extended props for columns -->
      </ActionGroup>

      <ActionGroup type="Procedures">
         <Action id="sqlserver-procedures-create" label="Create Procedure" reload="true" icon="add"
                 doclink="http://www.dbvis.com/doclink/create-procedure">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Procedure Name" name="procedureName" style="text"/>

            <Input label="Parameters" style="separator"/>

            <Input name="parameters" style="grid">
               <Arg name="output" value="${name} ${type} ${direction}"/>
               <Arg name="newline" value=", "/>

               <Input name="name" label="Name" style="text">
                  <Default>@parm</Default>
               </Input>
               <Input name="direction" label="Direction" style="list">
                  <Values>|OUTPUT</Values>
               </Input>
               <Input name="type" label="Type" style="text">
                  <Default>VARCHAR(20)</Default>
               </Input>
            </Input>

            <SetVar name="_parameters" value='#parameters.trim().equals("") ? "" : #parameters'/>
            <Command exectype="asis">
               <SQL>
                  <![CDATA[
CREATE PROCEDURE [${schema}].${QB}${procedureName}${QE}
${_parameters}
AS
/* Procedure body */
                  ]]>
               </SQL>
            </Command>
            <Confirm>
               Create procedure ${procedureName}?
            </Confirm>
            <Result>
               Procedure ${procedureName} created!
            </Result>
         </Action>
      </ActionGroup>

      <ActionGroup type="Procedure">
         <Action id="sqlserver-procedure-drop" label="Drop Procedure" reload="true" icon="remove">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Procedure" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Command>
               <SQL>
                  <![CDATA[
                  drop procedure [${schema}].[${objectname}]
                  ]]>
               </SQL>
            </Command>
            <Confirm>
               Really drop procedure ${schema}.${objectname}?
            </Confirm>
            <Result>
               Procedure ${schema}.${objectname} dropped!
            </Result>
         </Action>

         <Action id="sqlserver-procedure-rename" label="Rename Procedure" reload="true" icon="rename">
            <Message>
               <![CDATA[<html>
                 Warning: Changing an object or column name could break existing stored procedures, cached statements or other compiled objects.
               ]]>
            </Message>            
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Procedure" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Input label="New Procedure Name" name="newProcedure" style="text"/>
            <Command>
               <SQL>
                  <![CDATA[exec sp_rename [${schema}.${objectname}], ${QB}${newProcedure}${QE}]]></SQL>
            </Command>
            <Confirm>
               Confirm rename of procedure ${schema}.${objectname} to
               ${newProcedure}?
            </Confirm>
            <Result>
               Procedure ${objectname} renamed to ${newProcedure}!
            </Result>
         </Action>

         <Action id="sqlserver-procedure-export" label="Export Procedure" icon="export"
                 class="procedureExport"
                 doclink="http://www.dbvis.com/doclink/export-code-object"/>

         <Separator/>

         <Action id="sqlserver-procedure-script" label="Script Procedure" icon="scriptObject"
                 class="sqlBuilder"
                 classargs="script-dialog,CALL,CREATE,DROP"/>
      </ActionGroup>

      <ActionGroup type="Functions">
         <Action id="sqlserver-functions-create" label="Create Function" reload="true" icon="add"
                 doclink="http://www.dbvis.com/doclink/create-function">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Function Name" name="functionName" style="text"/>
            <Input label="Return Data Type" name="returns" style="text">
               <Default>VARCHAR(20)</Default>
            </Input>

            <Input label="Parameters" style="separator"/>

            <Input name="parameters" style="grid">
               <Arg name="output" value="${name} ${type}"/>
               <Arg name="newline" value=", "/>

               <Input name="name" label="Name" style="text">
                  <Default>@parm</Default>
               </Input>
               <Input name="type" label="Type" style="text">
                  <Default>VARCHAR(20)</Default>
               </Input>
            </Input>

            <SetVar name="_parameters" value='#parameters.trim().equals("()") ? "" : "(" + #parameters + ")"'/>
            <Command exectype="asis">
               <SQL>
                  <![CDATA[
CREATE FUNCTION [${schema}].${QB}${functionName}${QE}
${_parameters}
RETURNS ${returns}
AS
BEGIN
  /* Function body */
  RETURN NULL
END
                  ]]>
               </SQL>
            </Command>
            <Confirm>
               Create function "${schema}".${functionName}?
            </Confirm>
            <Result>
               Function ${schema}.${functionName} created!
            </Result>
         </Action>
      </ActionGroup>

      <ActionGroup type="Function">
         <Action id="sqlserver-function-drop" label="Drop Function" reload="true" icon="remove">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Function" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Command>
               <SQL>
                  <![CDATA[
                  drop function [${schema}].[${objectname}]
                  ]]>
               </SQL>
            </Command>
            <Confirm>
               Really drop function ${schema}.${objectname}?
            </Confirm>
            <Result>
               Function ${schema}.${objectname} dropped!
            </Result>
         </Action>

         <Action id="sqlserver-function-rename" label="Rename Function" reload="true" icon="rename">
            <Message>
               <![CDATA[<html>
                 Warning: Changing an object or column name could break existing stored procedures, cached statements or other compiled objects.
               ]]>
            </Message>            
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Function" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Input label="New Function Name" name="newFunction" style="text"/>
            <Command>
               <SQL>
                  <![CDATA[exec sp_rename [${schema}.${objectname}], ${QB}${newFunction}${QE}]]></SQL>
            </Command>
            <Confirm>
               Confirm rename of function ${schema}.${objectname} to
               ${newFunction}?
            </Confirm>
            <Result>
               Function ${objectname} renamed to ${newFunction}!
            </Result>
         </Action>

         <Action id="sqlserver-function-export" label="Export Function" icon="export"
                 class="functionExport"
                 doclink="http://www.dbvis.com/doclink/export-code-object"/>

         <Separator/>

         <Action id="sqlserver-function-script" label="Script Function" icon="scriptObject"
                 class="sqlBuilder"
                 classargs="script-dialog,CALL,CREATE,DROP"/>
      </ActionGroup>

      <ActionGroup type="Sequences">
         <Action id="sqlserver-sequences-create" label="Create Sequence" reload="true" icon="add">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
             <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Sequence Name" name="sequenceName" style="text"/>
            <Input label="Start With" name="startWith" style="text">
               <Default>1</Default>
            </Input>
            <Input label="Type" name="type" style="list">
               <Values>tinyint|smallint|int|bigint|decimal</Values>
               <Default>bigint</Default>
            </Input>
            <Input label="Start With" name="startWith" style="text">
               <Default>1</Default>
            </Input>
            <Input label="Increment By" name="increment" style="text">
               <Default>1</Default>
            </Input>
            <Input label="Cycle" name="cycle" style="radio">
               <Values>cycle|no cycle</Values>
               <Labels>Cycle|No Cycle</Labels>
               <Default>no cycle</Default>
            </Input>
            <Input label="Cached Values" name="cache" style="text">
               <Default>20</Default>
            </Input>
            <Command>
               <SQL>
                  <![CDATA[create sequence [${schema}].${QB}${sequenceName}${QE} as ${type} start with ${startWith} increment by ${increment} no maxvalue no minvalue ${cycle} cache ${cache}]]>
               </SQL>
            </Command>
            <Result>
               Sequence ${schema}.${sequenceName} created!
            </Result>
         </Action>
      </ActionGroup>

      <ActionGroup type="Sequence">
         <Action id="sqlserver-sequence-drop" label="Drop Sequence" reload="true" icon="remove">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Sequence" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Command>
               <SQL>
                  <![CDATA[
                  drop sequence [${schema}].[${objectname}]
                  ]]>
               </SQL>
            </Command>
            <Confirm>
               Really drop sequence ${schema}.${objectname}?
            </Confirm>
            <Result>
               Sequence ${schema}.${objectname} dropped!
            </Result>
         </Action>
      </ActionGroup>

      <ActionGroup type="Synonyms">
         <Action id="sqlserver-synonyms-create" label="Create Synonym" reload="true" icon="add">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Synonym Name" name="synObject" style="text"/>
            <Input label="Target Database" name="targetDb" style="list">
                <Values>
                  <Command idref="getCatalogs"/>
               </Values>
               <Default>${catalog}</Default>
            </Input>
                  
            <Input label="Target Object Owner" name="targetOwner" style="list" runsetdefaultwhenvaluechanged="true">
               <Values>
                   <Command idref="sqlserver.getSchemas">
                     <Input name="catalog" value="${targetDb}"/>
                  </Command>
               </Values>
               <Default>${schema}</Default>
            </Input>
            <Input label="Target Object Name" name="targetObject" style="text"/>

            <Command>
               <SQL>
                  <![CDATA[create synonym [${schema}].${QB}${synObject}${QE} for [${targetDb}].[${targetOwner}].[${targetObject}]]]>
               </SQL>
            </Command>
            <Result>
               Synonym ${synOwner}.${synObject} created!
            </Result>
         </Action>
      </ActionGroup>

      <ActionGroup type="Synonym">
         <Action id="sqlserver-synonym-drop" label="Drop Synonym" reload="true" icon="remove">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Schema" style="text" editable="false">
               <Default>${schema}</Default>
            </Input>
            <Input label="Synonym" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Command>
               <SQL>
                  <![CDATA[drop synonym [${schema}].[${objectname}]]]>
               </SQL>
            </Command>
            <Confirm>
               Really drop synonym ${schema}.${objectname}?
            </Confirm>
            <Result>
               Synonym ${schema}.${objectname} has been dropped!
            </Result>
         </Action>
      </ActionGroup>

      <ActionGroup type="Jobs">
         <Action id="sqlserver-jobs-create" label="Create Job" reload="true" icon="add">
            <Input name="jobName" label="Job Name" style="text"
                   tip="The name of the job. The name must be unique and cannot contain the percent (%) character"/>

            <Input name="enabled" label="Enabled" style="check">
                <Values>1|0</Values>
                <Default>1</Default>
            </Input>

            <Input name="desc" label="Description" style="text-editor"
                   tip="Specify an optional description here">
               <Arg name="height" value="30"/>
            </Input>

            <Input label="Category" name="category" style="list" editable="false">
               <Values>
                  <Command>
                     <SQL>
                        <![CDATA[SELECT CAST ( category_id AS varchar) FROM msdb.dbo.syscategories order by category_id]]>
                     </SQL>
                  </Command>
               </Values>
               <Labels>
                  <Command>
                     <SQL>
                        <![CDATA[SELECT name FROM msdb.dbo.syscategories order by category_id;]]>
                     </SQL>
                  </Command>
               </Labels>
               <Default>0</Default>
            </Input>
            <SetVar name="_categoryDDL" value='#category.equals("") ? "" : ", @category_id =" + #category'/>

            <Input name="owner_login_name" label="Owner Login Name" style="text"
                   tip="The name of the login that owns the job. login is sysname, with a default of NULL, which is interpreted as 
            the current login name. Only members of the sysadmin fixed server role can set or change this value."/>
            <Input label="Target Local Server" name="targetLocal" style="check">
               <Values>DoTarget</Values>
               <Default>DoTarget</Default>
            </Input>
            <SetVar name="_addJobServerDDL" value="#targetLocal.equals('DoTarget') ? 
             'EXEC msdb.dbo.sp_add_jobserver @job_name = N\'${jobName}\';' : ''"/>

            <Command>
               <SQL>
                  <![CDATA[
EXEC msdb.dbo.sp_add_job @job_name = N'${jobName}'
   , @enabled = ${enabled}
   , @description = N'${desc}' 
   ${_categoryDDL}
   , @owner_login_name = N'${owner_login_name}';
   ${_addJobServerDDL}
                ]]>
               </SQL>
            </Command>
            <Confirm>
               Really create job ${objectname}?
            </Confirm>
            <Result>
               Job ${objectname} created!
            </Result>
         </Action>
      </ActionGroup>

      <ActionGroup type="Job">

         <!-- Edit Job  : EXEC sp_update_job  -->
         <Action id="sqlserver-jobs-job-edit" label="Edit" reload="true">
            <Input name="jobName" label="Job Name" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Input name="newJobName" label="New Job Name" style="text" editable="true">
               <Default>${objectname}</Default>
            </Input>

            <Input name="desc" label="Description" style="text-editor"
                   tip="Specify an optional description here">
               <Arg name="height" value="30"/>
               <Default>${sqlserver.getAgentJobs.JobDescription}</Default>
            </Input>
            <SetVar name="_decriptionDDL" value="#desc.equals(#sp.getProperty('dbvis.ShowNullAs')) or #desc.equals('No description available.') ? '' : ', @description=N\'' + #desc + '\''"/>

            <!-- SELECT step_id, step_name  FROM sysjobsteps js where job_id = '${sqlserver.getAgentJobs.JobID}' order by step_id asc; -->
            <Input label="Start Step Id" name="startStepId" style="list" editable="false">
               <Values>
                  <Command>
                     <SQL>
                        <![CDATA[SELECT CAST (step_id AS varchar) FROM msdb.dbo.sysjobsteps js where job_id = '${sqlserver.getAgentJobs.JobID}' order by step_id asc]]>
                     </SQL>
                  </Command>
               </Values>
               <Labels>
                  <Command>
                     <SQL>
                        <![CDATA[SELECT step_name  FROM msdb.dbo.sysjobsteps js where job_id = '${sqlserver.getAgentJobs.JobID}' order by step_id asc ]]>
                     </SQL>
                  </Command>
               </Labels>
               <Default>${sqlserver.getAgentJobs.JobStartStepId}</Default>
            </Input>

            <SetVar name="_startStepIdDDL" value="#util.isNullOrWhitespace(#startStepId) ? '' : ', @start_step_id=' + #startStepId"/>

            <Input label="Category" name="category" style="list" editable="true">
               <Values>
                  <Command>
                     <SQL>
                        <![CDATA[SELECT name FROM msdb.dbo.syscategories order by category_id]]>
                     </SQL>
                  </Command>
               </Values>
               <Default>${sqlserver.getAgentJobs.JobCategory}</Default>
            </Input>

            <SetVar name="_categoryDDL" value="#util.isNull(#category) ? '' : ', @category_name = N\'' + #category + '\''"/>

            <Input name="ownerLogin" label="Owner Login Name" style="text"
                   tip="The name of the login that owns the job. login is sysname, with a default of NULL, which is interpreted as 
            the current login name. Only members of the sysadmin fixed server role can set or change this value.">
               <Default>${sqlserver.getAgentJobs.JobOwner}</Default>
            </Input>

            <SetVar name="_ownerLoginDDL" value="#util.isNullOrWhitespace(#ownerLogin) ? '' : ', @owner_login_name=N\'' + #ownerLogin + '\''"/>

            <Command>
               <SQL>
                  <![CDATA[
EXEC msdb.dbo.sp_update_job  @job_name = N'${objectname}'
     , @new_name =  N'${newJobName}'   ${_decriptionDDL}
     ${_startStepIdDDL}
     ${_categoryDDL}
     ${_ownerLoginDDL}
                 ]]>
               </SQL>
            </Command>
            <Confirm>
               <![CDATA[Really update tob ${objectname}?]]></Confirm>
            <Result>Job ${objectname} updated!</Result>
         </Action>
         <!-- END  Edit Job  -->

         <!-- Edit Job Notifications : EXEC sp_update_job  -->
         <Action id="sqlserver-jobs-job-edit-notifications" label="Edit Notifications" reload="true">
            <Input name="jobName" label="Job Name" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>

            <Message>Actions to perform when the job ends.</Message>

            <Input label="Mail" style="note" linebreak="false" tip="Send mail actions"/>

            <Input label="Send" name="emailLevel" style="list" editable="false" linebreak="false">
               <Values>0|1|2|3</Values>
               <Labels>Never|On success|On failure|Always</Labels>
               <Default>${sqlserver.getAgentJobs.notify_level_email}</Default>
               <!--  From DB ${sqlserver.getAgentJobs.notify_level_email}-->
            </Input>

            <Input label="to Operator" name="emailOper" style="list" editable="false" linebreak="true">
               <Values>
                  <Command>
                     <SQL>
                        <![CDATA[SELECT name FROM msdb.dbo.sysoperators order by id]]>
                     </SQL>
                  </Command>
               </Values>
               <Default>${sqlserver.getAgentJobs.OperatorEmail}</Default>
            </Input>

            <SetVar name="_emailNotifDDL" value="#emailLevel == 0 ? ' @notify_level_email=2, @notify_email_operator_name=N\'\''
			: '@notify_level_email = ' + #emailLevel + ', @notify_email_operator_name=N\'' + #emailOper + '\'' "/>

            <Input label="Pager:" style="note" linebreak="false" tip="Pager actions"/>
            <Input label="Send" name="pagerLevel" style="list" editable="false" linebreak="false">
               <Values>0|1|2|3</Values>
               <Labels>Never|On success|On failure|Always</Labels>
               <Default>${sqlserver.getAgentJobs.notify_level_page}</Default>
            </Input>

            <Input label="to Operator" name="pagerOper" style="list" editable="false" linebreak="true">
               <Values>
                  <Command>
                     <SQL>
                        <![CDATA[SELECT name FROM msdb.dbo.sysoperators order by id]]>
                     </SQL>
                  </Command>
               </Values>
               <Default>${sqlserver.getAgentJobs.OperatorPager}</Default>
            </Input>

            <SetVar name="_pagerNotifDDL" value="#pagerLevel == 0 ? ' @notify_level_page=2, @notify_page_operator_name=N\'\'' 
			: '@notify_level_page = ' + #pagerLevel + ', @notify_page_operator_name=N\'' + #pagerOper + '\'' "/>

            <Input label="Net Send:" style="note" linebreak="false" tip="Net Send actions"/>
            <Input label="Send" name="netSendLevel" style="list" editable="false" linebreak="false">
               <Values>0|1|2|3</Values>
               <Labels>Never|On success|On failure|Always</Labels>
               <Default>${sqlserver.getAgentJobs.notify_level_netsend}</Default>
            </Input>
            <Input label="to Operator" name="netSendOper" style="list" editable="false" linebreak="true">
               <Values>
                  <Command>
                     <SQL>
                        <![CDATA[SELECT name FROM msdb.dbo.sysoperators order by id]]>
                     </SQL>
                  </Command>
               </Values>
               <Default>${sqlserver.getAgentJobs.OperatorNetSend}</Default>
            </Input>

            <SetVar name="_netSendNotifDDL" value="#netSendLevel == 0 ? ' @notify_level_netsend=2, @notify_netsend_operator_name=N\'\'' 
			: '@notify_level_netsend = ' + #netSendLevel + ', @notify_netsend_operator_name=N\'' + #netSendOper + '\'' "/>

            <Input label="Write to Windows Application Event Log" name="eventLogLevel" style="list" editable="false" linebreak="true">
               <Values>0|1|2|3</Values>
               <Labels>Never|On success|On failure|Always</Labels>
               <Default>${sqlserver.getAgentJobs.notify_level_eventlog}
               </Default>
            </Input>

            <Input label="Automatically Delete Job" name="deleteLevel" style="list" editable="false" linebreak="true">
               <Values>0|1|2|3</Values>
               <Labels>Never|On success|On failure|Always</Labels>
               <Default>${sqlserver.getAgentJobs.delete_level}</Default>
            </Input>

            <Command>
               <SQL>
                  <![CDATA[
EXEC msdb.dbo.sp_update_job @job_name = N'${jobName}',
       ${_emailNotifDDL}, 
       ${_pagerNotifDDL}, 
	   ${_netSendNotifDDL}, 
	   @notify_level_eventlog = ${eventLogLevel}, 
	   @delete_level= ${deleteLevel}
                 ]]>
               </SQL>
            </Command>
            <Confirm>
               <![CDATA[Really update job ${objectname}?]]></Confirm>
            <Result>Job ${objectname} updated!</Result>
         </Action>
         <!-- END  Edit Job Notifications -->


         <Action id="sqlserver-job-delete" label="Delete Job" reload="true" icon="remove">
            <Input name="jobName" label="Job Name" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>

            <Input label="Delete History" name="deleteHistory" style="check"
                   tip="If checked the Job History will be deleted as well">
               <Values>DoDelete</Values>
               <Default>DoDelete</Default>
            </Input>
            <SetVar name="_doDeleteHistoryDDL" value="#deleteHistory.equals('DoDelete') ? 
             ', @delete_history = 1' : ', @delete_history = 0'"/>

            <Input label="Delete Unused Schedule" name="deleteUnusedSched" style="check"
                   tip="If checked and this Job is the only job using its schedule the schedule will be removed">
               <Values>DoDelete</Values>
               <Default>DoNotDelete</Default>
            </Input>
            <SetVar name="_doDeleteUnusedSchedDDL" value="#deleteUnusedSched.equals('DoDelete') ? 
             ', @delete_unused_schedule = 1' : ', @delete_unused_schedule = 0'"/>

            <Command>
               <SQL>
<![CDATA[
EXEC msdb.dbo.sp_delete_job  @job_name = N'${objectname}'
  ${_doDeleteHistoryDDL} 
  ${_doDeleteUnusedSchedDDL}
]]>
               </SQL>
            </Command>
            <Confirm>
               Really delete job ${objectname}?
            </Confirm>
            <Result>
               Job ${objectname} deleted!
            </Result>
         </Action>


         <Action id="sqlserver-job-setState" label="Enable/Disable Job" reload="true">
            <Input name="jobName" label="Job Name" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Input label="Current Job Status" name="currentEventStatus" style="text" editable="false">
               <Default>
                  <Command>
                     <SQL>
                        <![CDATA[
select CASE sj.enabled
     WHEN 0 THEN 'DISABLED'
     WHEN 1 THEN 'ENABLED'
   END AS Status
   from msdb.dbo.sysjobs sj where name = '${objectname}'
   ]]>
                     </SQL>
                  </Command>
               </Default>
            </Input>
            <SetVar name="_newDefaultStatus" value="#currentEventStatus.equals('DISABLED') ? '1' : '0'"/>

            <Input label="New Event Status" name="newStatus" style="radio">
               <Values>1|0</Values>
               <Labels>ENABLE|DISABLE</Labels>
               <Default>${_newDefaultStatus}</Default>
            </Input>

            <Command>
               <SQL>
                  <![CDATA[EXEC msdb.dbo.sp_update_job @job_name = N'${objectname}', @enabled = ${newStatus}]]>
               </SQL>
            </Command>
            <Confirm>
               <![CDATA[Really update job ${objectname}?]]></Confirm>
            <Result>Job ${objectname} updated!</Result>
         </Action>

         <!-- Create Job Step : EXEC sp_add_jobstep  -->
         <Action id="sqlserver-jobs-job-create-step" label="Create Step" reload="true">
            <Input name="jobName" label="Job Name" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Input name="stepName" label="Step Name" style="text" editable="true"/>
            <Input name="stepID" label="Step ID" style="text" editable="true"/>
            <SetVar name="_stepIdDDL" value="#stepID.equals('') ? '' : ', @step_id = ' + #stepID "/>

            <Input label="Type" name="subsystem" style="list" editable="true">
               <Values>
                  <Command>
                     <SQL>
                        <![CDATA[SELECT subsystem FROM msdb.dbo.syssubsystems order by subsystem_id]]>
                     </SQL>
                  </Command>
               </Values>
               <Default>TSQL</Default>
            </Input>
            <SetVar name="_subsystemDDL" value="#subsystem.equals('') ? '' : ', @subsystem = N\'' + #subsystem + '\''"/>

            <!-- In MSS there is a possibility to specify "run as" a different account for a job step
                 have not seen this in the TSQL stored procedures  -->
            <Input name="command" label="Command" style="text-editor"
                   tip="The commands to be executed by SQLServerAgent service through subsystem.">
               <Arg name="height" value="50"/>
            </Input>
            <Input label="Database" name="database" style="list" editable="true">
               <Values>
                  <Command idref="getCatalogs"/>
               </Values>
            </Input>
            <SetVar name="_databaseDDL" value="#database.equals('') ? '' : ', @database_name = N\'' + #database + '\''"/>


            <Input label="Database User" name="databaseUser" style="text" editable="true"
                   tip="The name of the user account to use when executing a Transact-SQL step. user is sysname, with a default of NULL. When user is NULL, the step runs in the job owner's user context on database"/>
            <SetVar name="_databaseUserDDL" value="#databaseUser.equals('') ? '' : ', @database_user_name = N\'' + #databaseUser + '\''"/>

            <Input name="cmdexecSuccessCode" label="Cmdexec Success Code" style="text" editable="true"
                   tip="The value returned by a CmdExec subsystem command to indicate that command executed successfully. code is int, with a default of 0">
               <Default>0</Default>
            </Input>

            <Input label="On Success Action" name="onSuccessAction" style="list" editable="false" linebreak="false">
               <Values>1|2|3|4</Values>
               <Labels>Quit with success|Quit with failure|Go to next step|Go to
                  step ID
               </Labels>
               <Default>3</Default>
               <!--  MS documentation says 1 is default  -->
            </Input>
            <Input label="Step ID" name="onSuccessStepId" style="text" editable="true" linebreak="true"
                   tip="Only applicable if [On Success Action] is [Go to step ID] "/>
            <SetVar name="_onSuccessStepIdDDL" value="#onSuccessAction == 4 ? ', @on_success_step_id = ' + #onSuccessStepId  : ''"/>

            <Input label="On Fail Action" name="onFailAction" style="list" editable="false" linebreak="false">
               <Values>1|2|3|4</Values>
               <Labels>Quit with success|Quit with failure|Go to next step|Go to
                  step ID
               </Labels>
               <Default>2</Default>
            </Input>
            <Input label="On Failure Step ID" name="onFailureStepId" style="text" editable="true" linebreak="true"
                   tip="Only applicable if [On Failure Action] is [Go to step ID] "/>
            <SetVar name="_onFailStepIdDDL" value="#onFailAction == 4 ? ', @on_fail_step_id = ' + #onFailureStepId  : ''"/>

            <Input name="retryAttempts" label="Retry Attempts" style="text" editable="true"
                   tip="The number of retry attempts to use if this step fails">
               <Default>0</Default>
            </Input>

            <Input name="retryInterval" label="Retry Interval" style="text" editable="true"
                   tip="The amount of time in minutes between retry attempts">
               <Default>0</Default>
            </Input>

            <Input name="outputFileName" label="Output File Name" style="text" editable="true"
                   tip="The name of the file in which the output of this step is saved.">
            </Input>
            <SetVar name="_outputFilenameDDL" value="#outputFileName.equals('') ? '' : ', @output_file_name = N\'' + #outputFileName + '\''"/>

            <Input label="Flags" name="flags" style="list" editable="false">

               <!-- Values 32, 64 Introduced in 2008R2 (10.50)   -->
               <If test="#util.isDatabaseVersionGTE(10,50)">
                  <Labels>Overwrite output file|Append to output file|Write
                     Transact-SQL job step output to step history|Write log to
                     table (overwrite existing history)|Write log to table
                     (append to existing history)|Write all output to job
                     history|Create a Windows event to use as a signal for the
                     Cmd jobstep to abort
                  </Labels>
                  <Values>0|2|4|8|16|32|64</Values>
               </If>
               <Else>
                  <Labels>Overwrite output file|Append to output file|Write
                     Transact-SQL job step output to step history|Write log to
                     table (overwrite existing history)|Write log to table
                     (append to existing history)
                  </Labels>
                  <Values>0|2|4|8|16</Values>
               </Else>
               <Default>0</Default>
            </Input>

            <Input name="proxyName" label="Proxy Name" style="text" editable="true"
                   tip="The name of the proxy that the job step runs as">
            </Input>
            <SetVar name="_proxyNameDDL" value="#proxyName.equals('') ? '' : ', @proxy_name = N\'' + #proxyName + '\''"/>

            <Command>
               <SQL>
                  <![CDATA[
                  EXEC msdb.dbo.sp_add_jobstep  @job_name = N'${jobName}'
                    ${_stepIdDDL}  
                    , @step_name = N'${stepName}'
                    ${_subsystemDDL}
                    , @command = N'${command}'
                    , @cmdexec_success_code = ${cmdexecSuccessCode} 
                    , @on_success_action = ${onSuccessAction}  ${_onSuccessStepIdDDL}  
                    , @on_fail_action = ${onFailAction}  ${_onFailStepIdDDL}  
                    ${_databaseDDL}  
                    ${_databaseUserDDL}  
                    , @retry_attempts = ${retryAttempts} 
                    , @retry_interval = ${retryInterval} 
                    ${_outputFilenameDDL}
                    , @flags = ${flags} 
                     ${_proxyNameDDL}  
                 ]]>
               </SQL>
            </Command>
            <Confirm>
               <![CDATA[Really create job step ${objectname}?]]></Confirm>
            <Result>Job step ${objectname} created!</Result>
         </Action>
         <!-- END  Action add job step-->

         <!-- Run the selected job -->
         <Action id="sqlserver-jobs-job-run" label="Start the job" reload="true">
            <Input name="jobName" label="Job Name" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>

            <Input label="Server Name" name="serverName" style="list" editable="true">
               <Values>DbVisLocalServer</Values>
               <Labels>Local Server</Labels>
               <Default>DbVisLocalServer</Default>
            </Input>
            <SetVar name="_serverNameDDL" value="#serverName.equals('DbVisLocalServer') ? '' : ', @server_name = N\'' + #serverName + '\''"/>

            <Input label="Start from Step" name="stepName" style="list" editable="true">
               <Values>
                  <Command>
                     <SQL>
                        <![CDATA[select step_name from msdb.dbo.sysjobsteps s WHERE s.job_id = '${sqlserver.getAgentJobs.jobID}' order by step_id]]>
                     </SQL>
                  </Command>
               </Values>
            </Input>
            <SetVar name="_stepNameDDL" value="#stepName.equals('') ? '' : ', @step_name = N\'' + #stepName + '\''"/>

            <Command>
               <SQL>
                  <![CDATA[
EXEC msdb.dbo.sp_start_job @job_name = N'${objectname}'
  ${_serverNameDDL}
  ${_stepNameDDL}
                 ]]>
               </SQL>
            </Command>
            <Confirm><![CDATA[Really start job ${objectname}?]]></Confirm>
            <Result>Job ${objectname} was started!</Result>
         </Action>

      </ActionGroup>

      <ActionGroup type="JobStep">

         <!-- Edit Job Step : Using procedure sp_add_jobstep  -->
         <Action id="sqlserver-jobs-job-step-edit" label="Edit Step" reload="true">
            <!-- Save some initial values to enable check if they are changed  -->
            <Input name="jobName" label="Job Name" style="text" editable="false">
               <Default>${theJobName}</Default>
            </Input>
            <Input name="stepID" label="Step ID" style="text" editable="false">
               <Default>${sqlserver.getAgentJobSteps.step_id}</Default>
            </Input>

            <Input name="stepName" label="Step Name" style="text" editable="true">
               <Default>${sqlserver.getAgentJobSteps.step_name}</Default>
            </Input>

            <Input label="Type" name="subsystem" style="list" editable="true">
               <Values>
                  <Command>
                     <SQL>
                        <![CDATA[SELECT subsystem FROM msdb.dbo.syssubsystems order by subsystem_id]]>
                     </SQL>
                  </Command>
               </Values>

               <Default>${sqlserver.getAgentJobSteps.subsystem}</Default>
            </Input>

            <SetVar name="_subsystemDDL" value="#util.isNull(#subsystem) ? '' : ', @subsystem = N\'' + #subsystem + '\''"/>

            <Input name="command" label="Command" style="text-editor"
                   tip="The commands to be executed by SQLServerAgent service through subsystem.">
               <Arg name="height" value="50"/>
               <Default>
                  <Command>
                     <SQL>
                        <![CDATA[SELECT command FROM msdb.dbo.sysjobsteps where job_id = '${sqlserver.getAgentJobSteps.job_id}' and step_id = ${sqlserver.getAgentJobSteps.step_id}]]>
                     </SQL>
                  </Command>
               </Default>
            </Input>

            <SetVar name="origCommand" value='#origCommand eq null  ? #command : #origCommand'/>

            <SetVar name="_commandDDL" value="#command.equals(#origCommand) ? '' : ', @command = N\'' + #command + '\''"/>

            <Input label="Database" name="database" style="list" editable="true">
               <Values>
                  <Command idref="getCatalogs"/>
               </Values>
               <Default>${sqlserver.getAgentJobSteps.database_name}</Default>
            </Input>
            <SetVar name="_databaseDDL" value="#util.isNull(#database) ? '' : ', @database_name = N\'' + #database + '\''"/>

            <Input label="Database User" name="databaseUser" style="text" editable="true"
                   tip="The name of the user account to use when executing a Transact-SQL step. user is sysname, with a default of NULL. When user is NULL, the step runs in the job owner's user context on database">
               <Default>${sqlserver.getAgentJobSteps.database_user_name}
               </Default>
            </Input>

            <SetVar name="_databaseUserDDL" value="#util.isNull(#databaseUser) ? '' : ', @database_user_name = N\'' + #databaseUser + '\''"/>

            <Input name="cmdexecSuccessCode" label="Cmdexec Success Code" style="text" editable="true"
                   tip="The value returned by a CmdExec subsystem command to indicate that command executed successfully. code is int, with a default of 0">
               <Default>${sqlserver.getAgentJobSteps.cmdexec_success_code}
               </Default>
            </Input>

            <Input label="On Success Action" name="onSuccessAction" style="list" editable="false" linebreak="false">
               <Values>1|2|3|4</Values>
               <Labels>Quit with success|Quit with failure|Go to next step|Go to
                  step ID
               </Labels>
               <Default>${sqlserver.getAgentJobSteps.on_success_action}
               </Default>
            </Input>
            <Input label="Step ID" name="onSuccessStepId" style="text" editable="true" linebreak="true"
                   tip="Only applicable if [On Success Action] is [Go to step ID] ">
               <Default>${sqlserver.getAgentJobSteps.on_success_step_id}
               </Default>
            </Input>
            <SetVar name="_onSuccessStepIdDDL" value="#onSuccessAction == 4 ? ', @on_success_step_id = ' + #onSuccessStepId  : ''"/>

            <Input label="On Fail Action" name="onFailAction" style="list" editable="false" linebreak="false">
               <Values>1|2|3|4</Values>
               <Labels>Quit with success|Quit with failure|Go to next step|Go to
                  step ID
               </Labels>
               <Default>${sqlserver.getAgentJobSteps.on_fail_action}</Default>
            </Input>
            <Input label="On Failure Step ID" name="onFailureStepId" style="text" editable="true" linebreak="true"
                   tip="Only applicable if [On Failure Action] is [Go to step ID] ">
               <Default>${sqlserver.getAgentJobSteps.on_fail_step_id}</Default>
            </Input>
            <SetVar name="_onFailStepIdDDL" value="#onFailAction == 4 ? ', @on_fail_step_id = ' + #onFailureStepId  : ''"/>

            <Input name="retryAttempts" label="Retry Attempts" style="text" editable="true"
                   tip="The number of retry attempts to use if this step fails">
               <Default>${sqlserver.getAgentJobSteps.retry_attempts}</Default>
            </Input>

            <Input name="retryInterval" label="Retry Interval" style="text" editable="true"
                   tip="The amount of time in minutes between retry attempts">
               <Default>${sqlserver.getAgentJobSteps.retry_interval}</Default>
            </Input>

            <Input name="outputFileName" label="Output File Name" style="text" editable="true"
                   tip="The name of the file in which the output of this step is saved.">
               <Default>${sqlserver.getAgentJobSteps.output_file_name}</Default>
            </Input>

            <SetVar name="_outputFilenameDDL" value="#util.isNull(#outputFileName) ? '' : ', @output_file_name = N\'' + #outputFileName + '\''"/>

            <Input label="Flags" name="flags" style="list" editable="false">
               <!-- Values 32, 64 Introduced in 2008R2 (10.50)   -->
               <If test="#util.isDatabaseVersionGTE(10,50)">
                  <Labels>Overwrite output file|Append to output file|Write
                     Transact-SQL job step output to step history|Write log to
                     table (overwrite existing history)|Write log to table
                     (append to existing history)|Write all output to job
                     history|Create a Windows event to use as a signal for the
                     Cmd jobstep to abort
                  </Labels>
                  <Values>0|2|4|8|16|32|64</Values>
               </If>
               <Else>
                  <Labels>Overwrite output file|Append to output file|Write
                     Transact-SQL job step output to step history|Write log to
                     table (overwrite existing history)|Write log to table
                     (append to existing history)
                  </Labels>
                  <Values>0|2|4|8|16</Values>
               </Else>
               <Default>${sqlserver.getAgentJobSteps.flags}</Default>
            </Input>

            <Input name="proxyName" label="Proxy Name" style="text" editable="true"
                   tip="The name of the proxy that the job step runs as">
               <Default>${sqlserver.getAgentJobSteps.ProxyName}</Default>
            </Input>
            <SetVar name="_proxyNameDDL" value="#util.isNull(#proxyName) ? '' : ', @proxy_name = N\'' + #proxyName + '\''"/>

            <Command>
               <SQL>
                  <![CDATA[
EXEC msdb.dbo.sp_update_jobstep  @job_name = N'${jobName}'
                    , @step_id = ${stepID}  
                    , @step_name = N'${stepName}'
                    ${_subsystemDDL}
                    ${_commandDDL}
                    , @cmdexec_success_code = ${cmdexecSuccessCode} 
                    , @on_success_action = ${onSuccessAction}  ${_onSuccessStepIdDDL}  
                    , @on_fail_action = ${onFailAction}  ${_onFailStepIdDDL}  
                    ${_databaseDDL}  
                    ${_databaseUserDDL}  
                    , @retry_attempts = ${retryAttempts} 
                    , @retry_interval = ${retryInterval} 
                    ${_outputFilenameDDL}
                    , @flags = ${flags} 
                     ${_proxyNameDDL}  
                 ]]>
               </SQL>
            </Command>
            <Confirm>
               <![CDATA[Really update job step ${objectname}?]]></Confirm>
            <Result>Job step ${objectname} updated!</Result>
         </Action>
         <!-- END  Action edit job step-->

         <!-- Copy Job Step : Using procedure sp_add_jobstep  -->
         <Action id="sqlserver-jobs-job-step-copy" label="Copy Step" reload="true">
            <Input name="jobName" label="Job Name" style="text" editable="false">
               <Default>${theJobName}</Default>
            </Input>
            <Input name="stepName" label="Step Name" style="text" editable="true">
               <Default>${sqlserver.getAgentJobSteps.step_name}-Copy</Default>
            </Input>
            <Input name="stepID" label="Step ID" style="text" editable="true"/>
            <SetVar name="_stepIdDDL" value="#stepID.equals('') ? '' : ', @step_id = ' + #stepID "/>

            <Input label="Type" name="subsystem" style="list" editable="true">
               <Values>
                  <Command>
                     <SQL>
                        <![CDATA[SELECT subsystem FROM msdb.dbo.syssubsystems order by subsystem_id]]>
                     </SQL>
                  </Command>
               </Values>

               <Default>${sqlserver.getAgentJobSteps.subsystem}</Default>
            </Input>
            <SetVar name="_subsystemDDL" value="#util.isNullOrWhitespace(#subsystem) ? '' : ', @subsystem = N\'' + #subsystem + '\''"/>

            <Input name="command" label="Command" style="text-editor"
                   tip="The commands to be executed by SQLServerAgent service through subsystem.">
               <Arg name="height" value="50"/>
               <Default>
                  <Command>
                     <SQL>
                        <![CDATA[SELECT command FROM msdb.dbo.sysjobsteps where job_id = '${sqlserver.getAgentJobSteps.job_id}' and step_id = ${sqlserver.getAgentJobSteps.step_id}]]>
                     </SQL>
                  </Command>
               </Default>
            </Input>
            <Input label="Database" name="database" style="list" editable="true">
               <Values>
                  <Command idref="getCatalogs"/>
               </Values>
               <Default>${sqlserver.getAgentJobSteps.database_name}</Default>
            </Input>
            <SetVar name="_databaseDDL" value="#util.isNullOrWhitespace(#subsystem) ? '' : ', @database_name = N\'' + #database + '\''"/>

            <Input label="Database User" name="databaseUser" style="text" editable="true"
                   tip="The name of the user account to use when executing a Transact-SQL step. user is sysname, with a default of NULL. When user is NULL, the step runs in the job owner's user context on database">
               <Default>${sqlserver.getAgentJobSteps.database_user_name}
               </Default>
            </Input>

            <SetVar name="_databaseUserDDL" value="#util.isNullOrWhitespace(#databaseUser) ? '' : ', @database_user_name = N\'' + #databaseUser + '\''"/>

            <Input name="cmdexecSuccessCode" label="Cmdexec Success Code" style="text" editable="true"
                   tip="The value returned by a CmdExec subsystem command to indicate that command executed successfully. code is int, with a default of 0">
               <Default>${sqlserver.getAgentJobSteps.cmdexec_success_code}
               </Default>
            </Input>

            <Input label="On Success Action" name="onSuccessAction" style="list" editable="false" linebreak="false">
               <Values>1|2|3|4</Values>
               <Labels>Quit with success|Quit with failure|Go to next step|Go to
                  step ID
               </Labels>
               <Default>${sqlserver.getAgentJobSteps.on_success_action}
               </Default>
            </Input>
            <Input label="Step ID" name="onSuccessStepId" style="text" editable="true" linebreak="true"
                   tip="Only applicable if [On Success Action] is [Go to step ID] ">
               <Default>${sqlserver.getAgentJobSteps.on_success_step_id}
               </Default>
            </Input>
            <SetVar name="_onSuccessStepIdDDL" value="#onSuccessAction == 4 ? ', @on_success_step_id = ' + #onSuccessStepId  : ''"/>

            <Input label="On Fail Action" name="onFailAction" style="list" editable="false" linebreak="false">
               <Values>1|2|3|4</Values>
               <Labels>Quit with success|Quit with failure|Go to next step|Go to
                  step ID
               </Labels>
               <Default>${sqlserver.getAgentJobSteps.on_fail_action}</Default>
            </Input>
            <Input label="On Failure Step ID" name="onFailureStepId" style="text" editable="true" linebreak="true"
                   tip="Only applicable if [On Failure Action] is [Go to step ID] ">
               <Default>${sqlserver.getAgentJobSteps.on_fail_step_id}</Default>
            </Input>
            <SetVar name="_onFailStepIdDDL" value="#onFailAction == 4 ? ', @on_fail_step_id = ' + #onFailureStepId  : ''"/>

            <Input name="retryAttempts" label="Retry Attempts" style="text" editable="true"
                   tip="The number of retry attempts to use if this step fails">
               <Default>${sqlserver.getAgentJobSteps.retry_attempts}</Default>
            </Input>

            <Input name="retryInterval" label="Retry Interval" style="text" editable="true"
                   tip="The amount of time in minutes between retry attempts">
               <Default>${sqlserver.getAgentJobSteps.retry_interval}</Default>
            </Input>

            <Input name="outputFileName" label="Output File Name" style="text" editable="true"
                   tip="The name of the file in which the output of this step is saved.">
               <Default>${sqlserver.getAgentJobSteps.output_file_name}</Default>
            </Input>
            <SetVar name="_outputFilenameDDL" value="#util.isNullOrWhitespace(#outputFileName) ? '' : ', @output_file_name = N\'' + #outputFileName + '\''"/>

            <Input label="Flags" name="flags" style="list" editable="false">
               <Values>0|2|4|8|16|32|64</Values>
               <Labels>Overwrite output file|Append to output file|Write
                  Transact-SQL job step output to step history|Write log to
                  table (overwrite existing history)|Write log to table (append
                  to existing history)|Write all output to job history|Create a
                  Windows event to use as a signal for the Cmd jobstep to abort
               </Labels>
               <Default>${sqlserver.getAgentJobSteps.flags}</Default>
            </Input>

            <Input name="proxyName" label="Proxy Name" style="text" editable="true"
                   tip="The name of the proxy that the job step runs as">
               <Default>${sqlserver.getAgentJobSteps.ProxyName}</Default>
            </Input>
            <SetVar name="_proxyNameDDL" value="#util.isNullOrWhitespace(#proxyName) ? '' : ', @proxy_name = N\'' + #proxyName + '\''"/>

            <Command>
               <SQL>
                  <![CDATA[
   EXEC msdb.dbo.sp_add_jobstep  @job_name = N'${jobName}' 
                    ${_stepIdDDL}  
                    , @step_name = N'${stepName}'
                    ${_subsystemDDL}
                    , @command = N'${command}'
                    , @cmdexec_success_code = ${cmdexecSuccessCode} 
                    , @on_success_action = ${onSuccessAction}  ${_onSuccessStepIdDDL}  
                    , @on_fail_action = ${onFailAction}  ${_onFailStepIdDDL}  
                    ${_databaseDDL}  
                    ${_databaseUserDDL}  
                    , @retry_attempts = ${retryAttempts} 
                    , @retry_interval = ${retryInterval} 
                    ${_outputFilenameDDL}
                    , @flags = ${flags} 
                     ${_proxyNameDDL}  
                 ]]>
               </SQL>
            </Command>
            <Confirm>
               <![CDATA[Really try to create job step ${objectname}?]]></Confirm>
            <Result>Job step ${objectname} created!</Result>
         </Action>
         <!-- END  Action add job step-->

         <!-- Remove step from job: Stored proc:                                 -->
         <!--   sp_delete_jobstep  @job_name  'job_name' ,  [ @step_id = step_id  -->

         <Action id="sqlserver-jobs-job-step-delete" label="Delete Job Step" reload="true" icon="remove" supportsmultipleobjects="false">
            <Input name="jobName" label="Job Name" style="text" editable="false">
               <Default>${theJobName}</Default>
            </Input>
            <Input name="stepName" label="Step Name" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Command>
               <SQL>
                  <![CDATA[EXEC msdb.dbo.sp_delete_jobstep  @job_name = N'${theJobName}',  @step_id =  ${jobStepID}]]>
               </SQL>
            </Command>
            <Confirm>
               Really delete step '${objectname}' from job ${theJobName}?
            </Confirm>
            <Result>
               Step deleted!
            </Result>
         </Action>
      </ActionGroup>

      <ActionGroup type="JobSchedules">

         <!-- Attach schedule to job: Stored proc: sp_attach_schedule -->

         <Action id="sqlserver-jobs-job-schedules-attach" label="Attach Schedule" reload="true" icon="add">
            <Input label="Schedule" name="schedule" style="list" editable="false">
               <Values>
                  <Command>
                     <SQL>
                        <![CDATA[SELECT cast ( schedule_id as VARCHAR) FROM msdb.dbo.sysschedules order by name, schedule_id]]>
                     </SQL>
                  </Command>
               </Values>
               <Labels>
                  <Command>
                     <SQL>
                        <![CDATA[SELECT name FROM msdb.dbo.sysschedules order by name, schedule_id]]>
                     </SQL>
                  </Command>
               </Labels>
            </Input>

            <Command>
               <SQL>
                  <![CDATA[EXEC msdb.dbo.sp_attach_schedule @job_name = N'${theJobName}', @schedule_id = ${schedule}]]>
               </SQL>
            </Command>
            <Confirm>
               Really add schedule to job ${theJobName}?
            </Confirm>
            <Result>
               Schedule added for job!
            </Result>
         </Action>
      </ActionGroup>

      <ActionGroup type="JobSchedule">

         <!-- Detach schedule from job: Stored proc: sp_detach_schedule -->
         <Action id="sqlserver-jobs-job-schedule-detach" label="Detach Schedule" reload="true" icon="remove">
            <Input name="jobName" label="Job Name" style="text" editable="false">
               <Default>${theJobName}</Default>
            </Input>
            <Input name="scheduleName" label="Schedule Name" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Input label="Delete Unused Schedule" name="deleteUnusedSched" style="check"
                   tip="If checked the schedule itself will also be deleted if it's not used by any other Job">
               <Values>DoDelete</Values>
               <Default>DoNotDelete</Default>
            </Input>
            <SetVar name="_doDeleteUnusedSchedDDL" value="#deleteUnusedSched.equals('DoDelete') ?
             ', @delete_unused_schedule = 1' : ', @delete_unused_schedule = 0'"/>

            <Command>
               <SQL>
                  <![CDATA[
                  EXEC msdb.dbo.sp_detach_schedule  @job_name = N'${theJobName}'
 ,  @schedule_id =  ${scheduleID}
 ${_doDeleteUnusedSchedDDL}
 ]]>
               </SQL>
            </Command>

            <Confirm>
               Really remove schedule '${objectname}' from job ${theJobName}?
            </Confirm>
            <Result>
               Schedule removed!
            </Result>
         </Action>

         <Action id="sqlserver-jobs-job-schedule-setState" label="Enable/Disable Schedule" reload="true">
            <Input name="scheduleName" label="Schedule Name" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Input label="Current Schedule Status" name="currentEventStatus" style="text" editable="false">
               <Default>
                  <Command>
                     <SQL>
                        <![CDATA[
select CASE sSchedule.enabled
      WHEN 0 THEN 'DISABLED'
      WHEN 1 THEN 'ENABLED'
   END AS Status
   from msdb.dbo.sysschedules sSchedule where name = '${objectname}'
   ]]>
                     </SQL>
                  </Command>
               </Default>
            </Input>
            <SetVar name="_newDefaultStatus" value="#currentEventStatus.equals('DISABLED') ? '1' : '0'"/>

            <Input label="New Event Status" name="newStatus" style="radio">
               <Values>1|0</Values>
               <Labels>ENABLE|DISABLE</Labels>
               <Default>${_newDefaultStatus}</Default>
            </Input>

            <Command>
               <SQL>
                  <![CDATA[EXEC msdb.dbo.sp_update_schedule @name = N'${objectname}', @enabled = ${newStatus}]]>
               </SQL>
            </Command>
            <Confirm>
               <![CDATA[Really update schedule state for ${objectname}?]]></Confirm>
            <Result>Schedule ${objectname} updated!</Result>
         </Action>

      </ActionGroup>

      <ActionGroup type="JobServers">
         <!--  sp_delete_jobserver  @job_name =  'job_name'  ,  @server_name =  'server' -->
         <Action id="sqlserver-jobs-job-targets-add" label="Add Server" reload="true" icon="add">
            <Input name="jobName" label="Job Name" style="text" editable="false">
               <Default>${theJobName}</Default>
            </Input>

            <Input label="Server Name" name="serverName" style="list" editable="true">
               <Values>DbVisLocalServer</Values>
               <Labels>Local Server</Labels>
            </Input>

            <SetVar name="_serverNameDDL" value="#serverName.equals('DbVisLocalServer') ? '' : ', @server_name = N\'' + #serverName + '\''"/>

            <Command>
               <SQL>
                  <![CDATA[EXEC msdb.dbo.sp_add_jobserver  @job_name = N'${theJobName}' ${_serverNameDDL}]]>
               </SQL>
            </Command>
            <Confirm>
               Really add server to job ${theJobName}?
            </Confirm>
            <Result>
               Server added to job ${theJobName}!
            </Result>
         </Action>
      </ActionGroup>

      <ActionGroup type="JobServer">
         <!--  sp_delete_jobserver  @job_name =  'job_name'  ,  @server_name =  'server' -->
         <Action id="sqlserver-jobs-job-targets-delete" label="Delete Server" reload="true" icon="remove">
            <Input name="jobName" label="Job Name" style="text" editable="false">
               <Default>${theJobName}</Default>
            </Input>
            <Input name="serverName" label="Server Name" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Command>
               <SQL>
                  <![CDATA[EXEC msdb.dbo.sp_delete_jobserver  @job_name = N'${theJobName}',  @server_name =  N'${objectname}']]>
               </SQL>
            </Command>
            <Confirm>
               Really remove server ${objectname} from job ${theJobName}?
            </Confirm>
            <Result>
               Job ${theJobName} is no longer running on server ${objectname}!
            </Result>
         </Action>
      </ActionGroup>

      <ActionGroup type="SchedulerSchedules">
         <ActionGroup label="Add Schedule">
            <!--  Recurring MONTHLY Schedule -->
            <Action id="sqlserver-serveragent-schedules-add-recurring-monthly" label="Add Recurring Monthly" reload="true">
               <Input name="scheduleName" label="Schedule Name" style="text" editable="true"/>

               <Input name="enabled" label="Enabled" style="check">
                  <Values>1|0</Values>
                  <Default>1</Default>
               </Input>

               <Input label="Type" name="freqType" style="radio">
                  <Labels>Day number|Week Day</Labels>
                  <Values>1|0</Values>
                  <Default>Once</Default>
               </Input>

               <SetVar name="_frequencyType" value='#freqType.equals("1") ? "16" : "32"'/>

               <Input label="Day Number:" style="note" linebreak="false"/>
               <Input name="dayNumber" label="" style="number" editable="true" tip="Only applicable if Day Number is selected">
                  <Default>1</Default>
               </Input>
               <Input label="of every" style="note" linebreak="false"/>
               <Input name="monthNumberDayNumber" label="" style="number" editable="true">
                  <Default>1</Default>
               </Input>
               <Input label="Month(s)" style="note" linebreak="true"/>


               <Input label="Week Day:" style="note" linebreak="false"/>
               <Input label="The" style="note" linebreak="false"/>
               <Input label="" name="daySeq" style="list">
                  <Labels>first|second|third|fourth|last</Labels>
                  <Values>1|2|4|8|16</Values>
                  <Default>1</Default>
               </Input>
               <Input label="" name="dayType" style="list">
                  <Labels>
                     Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Day|Weekday|Weekend
                     day
                  </Labels>
                  <Values>1|2|3|4|5|6|7|8|9|10</Values>
                  <Default>Once</Default>
               </Input>
               <Input label="of every" style="note" linebreak="false"/>
               <Input name="monthNumberWeekDay" label="" style="number" editable="true">
                  <Default>1</Default>
               </Input>
               <Input label="Month(s)" style="note" linebreak="true"/>

               <!-- freq_recurrence_factor. According to MS docs this is only used for freq_type is 8, 16, or 32.
                    With a default value of 0.
                    However MSS Management Studio generates @freq_recurrence_factor=1,
                    The Recurs every XX Day(s) is carried in the   @freq_interval parameter.   -->


               <!--
                  Frequency interval is depending on if freqType is  "Day Number"(1) or "Week Day"
                 "Day Number"(1) = #dayNumber
                 "Week Day" = #dayType
                -->
               <SetVar name="_freqInterval" value='#freqType.equals("1") ? #dayNumber : #dayType'/>

               <!--
                 freq_relative_interval is depending on if freqType is  "Day Number"(1) or "Week Day"
                 "Day Number"(1) = Should not be set
                "Week Day" = #daySeq
               -->
               <SetVar name="_freqRelativeIntervalDDL" value='#freqType.equals("1") ? ""  : ", @freq_relative_interval="  + #daySeq'/>

               <!--freq_recurrence_factor  -->
               <SetVar name="_freqReqFactor" value='#freqType.equals("1") ? #monthNumberDayNumber : #monthNumberWeekDay'/>

               <Input style="separator" label="Daily Frequency"/>

               <Input label="Occurs" name="occures" style="radio">
                  <Labels>Once At|Once Every</Labels>
                  <Values>1|0</Values>
                  <Default>Once</Default>
               </Input>

               <Input name="onceAt" label="Once At" style="number" editable="true"
                      tip="Time in 24 hour syntax including seconds. E.g. 221002">
                  <Default>000000</Default>
               </Input>

               <Input name="onceEvery" label="Once Every" style="number" editable="true" linebreak="false"
                      tip="The frequency">
                  <Default>1</Default>
               </Input>

               <Input label="" name="freqSubdayType" style="list" editable="false" linebreak="true">
                  <Values>8|4|2</Values>
                  <Labels>Hour(s)|Minute(s)|Second(s)</Labels>
                  <Default>8</Default>
               </Input>
               <Input label="" name="aNotherNote" style="note" linebreak="false"/>
               <Input name="startingAt" label="Starting at" style="text" editable="true" linebreak="false"
                      tip="Time in 24 hour syntax (HHMMSS) including seconds. E.g. 221002">
                  <Default>235959</Default>
               </Input>
               <Input name="endingAt" label="Ending at" style="text" editable="true" linebreak="true"
                      tip="Time in 24 hour syntax (HHMMSS) including seconds. E.g. 221002">
                  <Default>000200</Default>
               </Input>


               <Input style="separator" label="Duration"/>
               <Input name="startDate" label="Starting Date" style="text" editable="true" linebreak="false"
                      tip="Date in YYYYMMDD syntax. E.g. 20160226"/>
               <Input name="endDate" label="Ending Date" style="text" editable="true" linebreak="true"
                      tip="Date in YYYYMMDD syntax. E.g. 20160401. Blank means no end date"/>

               <!-- Special treatment for  interval related parameters depending on "Occur Once" or "Occur Every"
                  For occur Once
                 @freq_subday_type=1,  @freq_subday_interval=0, @active_start_time=<input field onceAt> ,

                 For occur Every
                  @freq_subday_type=<freqSubdayType>, @freq_subday_interval=<onceEvery>,
                  @active_start_time=<startingAt>,  @active_end_time=<endingAt>,
               -->

               <SetVar name="_occurDDL" value='#occures.equals("1") ?
                 "@freq_subday_type=1,  @freq_subday_interval=0, @active_start_time=" +#onceAt : 
                 " @freq_subday_type=" + #freqSubdayType + ", @freq_subday_interval=" + #onceEvery +
                ", @active_start_time=" + #startingAt + ", @active_end_time=" + #endingAt'/>

               <SetVar name="_activeEndDateDDL" value='#endDate.equals("") ?
                "" : 
                ", @active_end_date=" + #endDate'/>

               <Command>
                  <SQL>
                     <![CDATA[
EXEC msdb.dbo.sp_add_schedule  @schedule_name = N'${scheduleName}', @enabled=${enabled}
 , @freq_type=${_frequencyType}, @freq_interval=${_freqInterval}
 , ${_occurDDL} ${_freqRelativeIntervalDDL} 
 , @freq_recurrence_factor=${_freqReqFactor}
 , @active_start_date=${startDate} ${_activeEndDateDDL}
 ]]>
                  </SQL>
               </Command>
               <Confirm>
                  Really add monthly schedule ${scheduleName}?
               </Confirm>
               <Result>
                  The monthly schedule ${scheduleName} was added!
               </Result>
            </Action>

            <!--  Recurring WEEKLY Schedule -->
            <Action id="sqlserver-serveragent-schedules-add-recurring-weekly" label="Add Recurring Weekly" reload="true">
               <Input name="scheduleName" label="Schedule Name" style="text" editable="true"/>

               <Input name="enabled" label="Enabled" style="check">
                  <Values>1|0</Values>
                  <Default>1</Default>
               </Input>

               <Input label="Recurs every:" style="note" linebreak="false"/>

               <!-- freq_recurrence_factor  -->
               <Input name="freqReqFactor" label="" style="number" editable="true">
                  <Default>1</Default>
               </Input>
               <Input label="Week(s) on" style="note" linebreak="true" tip="Check selected week daus below"/>

               <Input label="" name="aNote" style="note" linebreak="false"/>
               <Input label="Mon" name="mon" style="check" linebreak="false">
                  <Values>2</Values>
               </Input>
               <Input label="Tue" name="tue" style="check" linebreak="false">
                  <Values>4</Values>
               </Input>
               <Input label="Wed" name="wed" style="check" linebreak="false">
                  <Values>8</Values>
               </Input>
               <Input label="Thu" name="thu" style="check" linebreak="false">
                  <Values>16</Values>
               </Input>
               <Input label="Fri" name="fri" style="check" linebreak="false">
                  <Values>32</Values>
               </Input>
               <Input label="" name="blankNote2" style="note" linebreak="false"/>
               <Input label="Sat" name="sat" style="check" linebreak="false">
                  <Values>64</Values>
               </Input>
               <Input label="Sun" name="sun" style="check" linebreak="true">
                  <Values>1</Values>
                  <Default>1</Default>
               </Input>

               <SetVar name="_sun" value='#sun.equals("") ? 0 : 1'/>
               <SetVar name="_mon" value='#mon.equals("") ? 0 : 2'/>
               <SetVar name="_tue" value='#tue.equals("") ? 0 : 4'/>
               <SetVar name="_wed" value='#wed.equals("") ? 0 : 8'/>
               <SetVar name="_thu" value='#thu.equals("") ? 0 : 16'/>
               <SetVar name="_fri" value='#fri.equals("") ? 0 : 32'/>
               <SetVar name="_sat" value='#sat.equals("") ? 0 : 64'/>

               <!-- Frequency type 8 (Weekly) The freq_interval is combined with an OR logical operator (BitMask )-->
               <SetVar name="_freqType" value="8"/>
               <SetVar name="_freqInterval" value="#_sun | #_mon | #_tue | #_wed | #_thu | #_fri | #_sat  "/>

               <Input style="separator" label="Daily Frequency"/>

               <Input label="Occurs" name="occures" style="radio">
                  <Labels>Once At|Once Every</Labels>
                  <Values>1|0</Values>
                  <Default>Once</Default>
               </Input>

               <Input name="onceAt" label="Once At" style="number" editable="true"
                      tip="Time in 24 hour syntax including seconds. E.g. 221002. Only applicable if [Once] is choosen above">
                  <Default>000000</Default>
               </Input>

               <Input name="onceEvery" label="Once Every" style="number" editable="true" linebreak="false"
                      tip="The frequency. Only applicable if [Every] is choosen above">
                  <Default>1</Default>
               </Input>

               <Input label="" name="freqSubdayType" style="list" editable="false" linebreak="true">
                  <Values>8|4|2</Values>
                  <Labels>Hour(s)|Minute(s)|Second(s)</Labels>
                  <Default>8</Default>
               </Input>
               <Input label="" name="aNotherNote" style="note" linebreak="false"/>
               <Input name="startingAt" label="Starting at" style="text" editable="true" linebreak="false"
                      tip="Time in 24 hour syntax (HHMMSS) including seconds. E.g. 221002">
                  <Default>235959</Default>
               </Input>
               <Input name="endingAt" label="Ending at" style="text" editable="true" linebreak="true"
                      tip="Time in 24 hour syntax (HHMMSS) including seconds. E.g. 221002">
                  <Default>000200</Default>
               </Input>

               <!-- freq_subday_type  -->
               <Input style="separator" label="Duration"/>
               <Input name="startDate" label="Starting Date" style="text" editable="true" linebreak="false"
                      tip="Date in YYYYMMDD syntax. E.g. 20160226"/>
               <Input name="endDate" label="Ending Date" style="text" editable="true" linebreak="true"
                      tip="Date in YYYYMMDD syntax. E.g. 20160401. Blank means no end date"/>

               <!-- Special treatment for  interval related parameters depending on "Occur Once" or "Occur Every"
                 For occur Once
                   @freq_subday_type=1,  @freq_subday_interval=0, @active_start_time=<input field onceAt> ,

                  For occur Every
                   @freq_subday_type=<freqSubdayType>, @freq_subday_interval=<onceEvery>,
                 @active_start_time=<startingAt>,  @active_end_time=<endingAt>,
               -->

               <SetVar name="_occurDDL" value='#occures.equals("1") ?
                "@freq_subday_type=1,  @freq_subday_interval=0, @active_start_time=" +#onceAt : 
               " @freq_subday_type=" + #freqSubdayType + ", @freq_subday_interval=" + #onceEvery +
               ", @active_start_time=" + #startingAt + ", @active_end_time=" + #endingAt'/>

               <SetVar name="_activeEndDateDDL" value='#endDate.equals("") ? 
                "" : 
                ", @active_end_date=" + #endDate'/>

               <Command>
                  <SQL>
                     <![CDATA[
EXEC msdb.dbo.sp_add_schedule  @schedule_name = N'${scheduleName}', @enabled=${enabled}
 , @freq_type=8, @freq_interval=${_freqInterval}
 , @freq_recurrence_factor=${freqReqFactor}
 , ${_occurDDL}  
 , @active_start_date=${startDate} ${_activeEndDateDDL}
 ]]>
                  </SQL>
               </Command>
               <Confirm>
                  Really add weekly schedule ${scheduleName}?
               </Confirm>
               <Result>
                  The weekly schedule ${scheduleName} was added!
               </Result>
            </Action>

            <!--  Recurring DAILY Schedule -->
            <Action id="sqlserver-serveragent-schedules-add-recurring-daily" label="Add Recurring Daily" reload="true">
               <Input name="scheduleName" label="Schedule Name" style="text" editable="true"/>

               <Input name="enabled" label="Enabled" style="check">
                  <Values>1|0</Values>
                  <Default>1</Default>
               </Input>

               <Input label="Recurs every:" style="note" linebreak="false"/>

               <!-- freq_recurrence_factor. According to MS docs this is only used for freq_type is 8, 16, or 32.
                    With a default value of 0.
                    However MSS Management Studio generates @freq_recurrence_factor=1,
                    The Recurs every XX Day(s) is carried in the   @freq_interval parameter.   -->

               <Input name="freqInterval" label="" style="number" editable="true">
                  <Default>1</Default>
               </Input>
               <Input label="Day(s)" style="note" linebreak="true"/>


               <SetVar name="_freqReqFactor" value="1"/>
               <!-- Frequency type 4 (daily) -->

               <Input style="separator" label="Daily Frequency"/>

               <Input label="Occurs" name="occures" style="radio">
                  <Labels>Once At|Once Every</Labels>
                  <Values>1|0</Values>
                  <Default>Once</Default>
               </Input>

               <Input name="onceAt" label="Once At" style="number" editable="true"
                      tip="Time in 24 hour syntax including seconds. E.g. 221002">
                  <Default>000000</Default>
               </Input>

               <Input name="onceEvery" label="Once Every" style="number" editable="true" linebreak="false"
                      tip="The frequency">
                  <Default>1</Default>
               </Input>

               <Input label="" name="freqSubdayType" style="list" editable="false" linebreak="true">
                  <!-- Value 2 -Seconds introduced in 2008  10.0 -->
                  <If test="#util.isDatabaseVersionGTE(10)">
                     <Values>8|4|2</Values>
                     <Labels>Hour(s)|Minute(s)|Second(s)</Labels>
                  </If>
                  <Else>
                     <Values>8|4</Values>
                     <Labels>Hour(s)|Minute(s)</Labels>
                  </Else>
                  <Default>8</Default>
               </Input>
               <Input label="" name="aNotherNote" style="note" linebreak="false"/>
               <Input name="startingAt" label="Starting at" style="text" editable="true" linebreak="false"
                      tip="Time in 24 hour syntax (HHMMSS) including seconds. E.g. 221002">
                  <Default>235959</Default>
               </Input>
               <Input name="endingAt" label="Ending at" style="text" editable="true" linebreak="true"
                      tip="Time in 24 hour syntax (HHMMSS) including seconds. E.g. 221002">
                  <Default>000200</Default>
               </Input>

               <!-- freq_subday_type  -->
               <Input style="separator" label="Duration"/>
               <Input name="startDate" label="Starting Date" style="text" editable="true" linebreak="false"
                      tip="Date in YYYYMMDD syntax. E.g. 20160226"/>
               <Input name="endDate" label="Ending Date" style="text" editable="true" linebreak="true"
                      tip="Date in YYYYMMDD syntax. E.g. 20160401. Blank means no end date"/>

               <!-- Special treatment for  interval related parameters depending on "Occur Once" or "Occur Every"
                For occur Once
                 @freq_subday_type=1,  @freq_subday_interval=0, @active_start_time=<input field onceAt> ,

                For occur Every
                 @freq_subday_type=<freqSubdayType>, @freq_subday_interval=<onceEvery>,
                 @active_start_time=<startingAt>,  @active_end_time=<endingAt>,
               -->

               <SetVar name="_occurDDL" value='#occures.equals("1") ?
                 "@freq_subday_type=1,  @freq_subday_interval=0, @active_start_time=" +#onceAt : 
                " @freq_subday_type=" + #freqSubdayType + ", @freq_subday_interval=" + #onceEvery +
                ", @active_start_time=" + #startingAt + ", @active_end_time=" + #endingAt'/>

               <SetVar name="_activeEndDateDDL" value='#endDate.equals("") ?
                "" : 
                ", @active_end_date=" + #endDate'/>

               <Command>
                  <SQL>
                     <![CDATA[
EXEC msdb.dbo.sp_add_schedule  @schedule_name = N'${scheduleName}', @enabled=${enabled}
 , @freq_type=4, @freq_interval=${freqInterval}
 , ${_occurDDL}  
 , @active_start_date=${startDate} ${_activeEndDateDDL}
 ]]>
                  </SQL>
               </Command>
               <Confirm>
                  Really add daily schedule ${scheduleName}?
               </Confirm>
               <Result>
                  The daily schedule ${scheduleName} was added!
               </Result>
            </Action>

            <!--  One Time Schedule -->
            <Action id="sqlserver-serveragent-schedules-add-onetime" label="Add one time" reload="true">
               <Input name="scheduleName" label="Schedule Name" style="text" editable="true"/>

               <Input name="enabled" label="Enabled" style="check">
                  <Values>1|0</Values>
                  <Default>1</Default>
               </Input>

               <Input name="date" label="Date" style="text" editable="true" linebreak="false"
                      tip="Date in YYYYMMDD syntax. E.g. 20160226"/>

               <Input name="time" label="Time" style="number" editable="true" linebreak="true"
                      tip="Time in 24 hour syntax including seconds. E.g. 221002">
                  <Default>000000</Default>
               </Input>

               <Command>
                  <SQL>
                     <![CDATA[
EXEC msdb.dbo.sp_add_schedule  @schedule_name = N'${scheduleName}', @enabled=${enabled}
   , @freq_type=1 
   , @active_start_date=${date} 
   , @active_start_time=${time}
]]>
                  </SQL>
               </Command>
               <Confirm>
                  Really add one time schedule ${scheduleName}?
               </Confirm>
               <Result>
                  The one time schedule ${scheduleName} was added!
               </Result>
            </Action>

            <!--  Other Schedule -->
            <Action id="sqlserver-serveragent-schedules-add-other" label="Add other" reload="true">
               <Input name="scheduleName" label="Schedule Name" style="text" editable="true"/>

               <Input name="enabled" label="Enabled" style="check">
                  <Values>1|0</Values>
                  <Default>1</Default>
               </Input>

               <Input label="Type" name="freqType" style="list" editable="false" linebreak="true">
                  <Values>64|128</Values>
                  <Labels>Start automatically when SQL Server Agent service
                     starts|Start whenever the CPU becomes idle
                  </Labels>
                  <Default>64</Default>
               </Input>

               <Command>
                  <SQL>
                     <![CDATA[
EXEC msdb.dbo.sp_add_schedule @schedule_name = N'${scheduleName}', @enabled=${enabled}, @freq_type=${freqType}
]]>
                  </SQL>
               </Command>
               <Confirm>
                  Really add schedule ${scheduleName}?
               </Confirm>
               <Result>
                  The schedule ${scheduleName} was added!
               </Result>
            </Action>

         </ActionGroup>
      </ActionGroup>

      <ActionGroup type="SchedulerSchedule">
         <Action id="sqlserver-serveragent-schedules-schedule-setState" label="Enable/Disable Schedule" reload="true">
            <Input name="scheduleName" label="Schedule Name" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Input label="Current Schedule Status" name="currentEventStatus" style="text" editable="false">
               <Default>
                  <Command>
                     <SQL>
                        <![CDATA[
                        select CASE sSchedule.enabled
                        WHEN 0 THEN 'DISABLED'
                        WHEN 1 THEN 'ENABLED'
                        END AS Status
                        from msdb.dbo.sysschedules sSchedule where name = '${objectname}'
                        ]]>
                     </SQL>
                  </Command>
               </Default>
            </Input>
            <SetVar name="_newDefaultStatus" value="#currentEventStatus.equals('DISABLED') ? '1' : '0'"/>

            <Input label="New Event Status" name="newStatus" style="radio">
               <Values>1|0</Values>
               <Labels>ENABLE|DISABLE</Labels>
               <Default>${_newDefaultStatus}</Default>
            </Input>

            <Command>
               <SQL>
                  <![CDATA[EXEC msdb.dbo.sp_update_schedule @name = N'${objectname}', @enabled = ${newStatus}]]>
               </SQL>
            </Command>
            <Confirm>
               <![CDATA[Really try to update schedule ${objectname}?]]></Confirm>
            <Result>Schedule ${objectname} updated!</Result>
         </Action>

         <!--  DELETE Schedule -->
         <Action id="sqlserver-serveragent-schedules-schedule-delete" label="Delete Schedule" reload="true" icon="remove">
            <Input name="scheduleName" label="Schedule Name" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Input label="Force delete" name="force" style="check"
                   tip="If checked the delete will be done even though the schedule is used">
               <Values>DoForce</Values>
               <Default>DoNotForce</Default>
            </Input>
            <SetVar name="_doForceDDL" value="#force.equals('DoForce') ? 
             ', @force_delete = 1' : ', @force_delete = 0'"/>
            <Command>
               <SQL>
                  <![CDATA[EXEC msdb.dbo.sp_delete_schedule @schedule_name=N'${objectname}' ${_doForceDDL}]]>
               </SQL>
            </Command>
            <Confirm>
               Really delete schedule ${objectname}?
            </Confirm>
            <Result>
               The Schedule ${objectname} was removed!
            </Result>
         </Action>
      </ActionGroup>

      <ActionGroup type="LinkedServer">
         <If test="#util.isLicensed()">
           <Action id="sqlserver-linkedserver-test" label="Test Connection" icon="testConnection" reload="false">
               <Command>
                  <SQL>
                     <![CDATA[
                     EXEC sp_testlinkedserver @servername = N'${linkedServer}';
                     @sleep 3000;
                     ]]>
                  </SQL>
               </Command>
               <Result>
                  Connection to linked server '${linkedServer}' verified OK!
               </Result>
           </Action>
           <Action id="sqlserver-linkedserver-drop" label="Drop Linked Server" icon="remove" reload="true">
	            <Command>
	               <SQL>
	                  <![CDATA[EXEC sp_dropserver @server = N'${linkedServer}';]]>
	               </SQL>
	            </Command>
	            <Confirm>
	               Confirm drop linked server '${linkedServer}'?
	            </Confirm>
	            <Result>
	               Linked server '${linkedServer}' dropped!
	            </Result>
           </Action>
            <ActionGroup type="Settings" label="Set Linked Server Options" >
               <Action id="sqlserver-linkedserver-setoptions-boolean" label="Enable/Disable Options" icon="Settings">
                  <Message type="info">For details about the various options, please refer to Microsoft's documentation on Stored Procedures for Distributed Queries.</Message>
                  <Input name="server" label="Linked Server" style="text" editable="false">
                     <Default>${linkedServer}</Default>
                  </Input>
                  <Input name="option_name" label="Option Name" style="list" editable="true" tip="The option to enable or disable">
                     <Values>collation compatible|data access|dist|lazy schema validation|pub|rpc|rpc out|sub|system|use remote collation|remote proc transaction promotion</Values>
                  </Input>
                  <Input name="option_value" label="Option Value" style="radio"
                     tip="Enabled (TRUE|on) or disabled (FALSE|off).">
                     <Values>TRUE|FALSE</Values>
                  </Input>
                  <Command>
                     <SQL>
                       <![CDATA[
                       EXEC sp_serveroption @server = N'${server}', @optname = N'${option_name}', @optvalue = N'${option_value}' ;]]>
                     </SQL>
                  </Command>
                  <Confirm>
                     Confirm set option '${option_name} = ${option_value}' in linked server '${linkedServer}'?
                  </Confirm>
                  <Result>
                     Option '${option_name} = ${option_value}' was set for linked server '${linkedServer}'!
                  </Result>
               </Action>
               <Action id="sqlserver-linkedserver-setoptions-integer" label="Set Timeout Options" icon="Settings">
                  <Message type="info">A linked server bla bla</Message>
                  <Input name="server" label="Linked Server" style="text" editable="false">
                     <Default>${linkedServer}</Default>
                  </Input>
                  <Input name="option_name" label="Option Name" style="list" editable="true" tip="The timeout option to set for the linked server connection.">
                     <Default>connect timeout</Default>
                     <Values>connect timeout|query timeout</Values>
                  </Input>
                  <Input name="option_value" label="Option Value" style="number" tip="Timeout in seconds, or 0 to use the default (sp_configure).">
                  <Default>0</Default>
                  </Input>
                  <Command>
                     <SQL>
                       <![CDATA[EXEC sp_serveroption @server = N'${server}', @optname = N'${option_name}', @optvalue = N'${option_value}' ;]]>
                     </SQL>
                  </Command>
                  <Confirm>
                     Confirm set option '${option_name} = ${option_value}' for linked server '${linkedServer}'?
                  </Confirm>
                  <Result>
                     Option '${option_name} = ${option_value}' was set for linked server '${linkedServer}'!
                  </Result>
               </Action>
               <Action id="sqlserver-linkedserver-setoptions-string" label="Set Remote Collation" icon="Settings">
                  <Message type="info">For more details, please refer to Microsoft's documentation on Stored Procedures for Distributed Queries.</Message>
                  <Input name="server" label="Linked Server" style="text" editable="false">
                     <Default>${linkedServer}</Default>
                  </Input>
                  <Input name="option_value" label="Collation Name" style="text" editable="true" tip="Any supported collation (or NULL).">
                     <Default>NULL</Default>
                  </Input>
                  <SetVar name="_option_value" value='#option_value.equals("NULL") ? "NULL" : "N&apos;"+#option_value+"&apos;"'/>
                  <Command>
                     <SQL>
                       <![CDATA[
                       EXEC sp_serveroption @server = N'${server}', 
                       @optname = N'collation name', 
                       @optvalue = ${_option_value};]]>
                     </SQL>
                  </Command>
                  <Confirm>
                     Confirm set collation '${option_value}' in linked server '${linkedServer}'?
                  </Confirm>
                  <Result>
                     Collation '${option_value}' set for '${linkedServer}'!
                  </Result>
               </Action>
            </ActionGroup>
           <ActionGroup label="Manage Remote Logins">
              <Action id="sqlserver-linkedserver-add-login" label="Add Login" icon="add">
                  <Message type="info">For details about the various options, please refer to Microsoft's documentation on Stored Procedures for Distributed Queries.</Message>
                  <Input name="self" label="Use Local Login" style="radio" tip="Map local login to remote server (or NULL for  no credentials).">
                     <Values>TRUE|FALSE|NULL</Values>
                     <Default>TRUE</Default>
                  </Input>
                  <Input name="localLogin" label="Local Login" style="text" editable="true" tip="The login on the local server, or NULL to map all logins."/>
                  <Input name="rmtUser" label="Remote User" style="text" editable="true" tip="The login on the remote server (if not mapping the local login)." />
                  <Input name="rmtPassword" label="Remote Password" style="password" editable="true" tip="The password on the remote server (if not mapping the local login)."/>
                  
                  <!-- Wrap complete arguments (key/value) since some should be omitted depending on other inputs -->
                  <SetVar name="_useSelf" value='#self.equals("NULL") ? "" : ", @useself = &apos;"+#self+"&apos;"'/>
                  <SetVar name="_localLogin" value='#localLogin.trim().equals("") ? "" : #localLogin.trim().equals("NULL") ? ", @locallogin = NULL" : ", @locallogin = N&apos;"+#localLogin+"&apos;"'/>
                  <SetVar name="_rmtUser" value='#rmtUser.trim().equals("") ? "" : ", @rmtuser = N&apos;"+#rmtUser+"&apos;"'/>
                  <!-- Split and rename the password key and data to avoid hiding all of it in SQL preview -->
                  <SetVar name="_rmtPWK1" value='#rmtPassword.trim().equals("") ? "" : ", @rmtpassword = N&apos;"'/> 
                  <SetVar name="_rmtPassword" value='#rmtPassword.trim().equals("") ? "" : #rmtPassword'/>
                  <SetVar name="_rmtPWK2" value='#rmtPassword.trim().equals("") ? "" : "&apos;"'/> 
      	          <Command>
                     <SQL>
                        <![CDATA[
                        EXEC sp_addlinkedsrvlogin @rmtsrvname = N'${linkedServer}' ${_useSelf}${_localLogin}${_rmtUser}${_rmtPWK1}${_rmtPassword}${_rmtPWK2}   
                        ]]>
                     </SQL>
      	          </Command>
      	          <Confirm>
      	               Confirm add login to linked server '${linkedServer}'?
      	          </Confirm>
                  <Result>
                     Login was added to '${linkedServer}'!
                  </Result>
                 </Action>
              <Action id="sqlserver-linkedserver-drop-login" label="Drop Linked Server Login" icon="remove">
   	            <Input name="login" label="Login (user id)" style="list" editable="true" tip="The login on the local server that has a mapping to the linked server (NULL represents the mapping for all local users).">
                  <Values>
                     <Command>
                        <SQL>
                           <![CDATA[
                           select ISNULL(p.name, 'NULL')
                           from sys.servers s
                               join sys.linked_logins l
                                   on s.server_id = l.server_id
                               left join sys.server_principals p
                                   on l.local_principal_id = p.principal_id
                           where s.is_linked = 1 and s.name=N'${linkedServer}'
                           ]]>
                        </SQL>
                     </Command>
                  </Values>
                </Input>
                <SetVar name="_login" value='#login.trim().equals("NULL") ? "NULL" : "N&apos;"+#login+"&apos;"'/>
   	            <Command>
   	               <SQL>
   	                  <![CDATA[
   	                  EXEC sp_droplinkedsrvlogin @rmtsrvname = N'${linkedServer}', @locallogin = ${_login}
   	                  ]]>
   	               </SQL>
   	            </Command>
   	            <Confirm>
   	               Confirm drop login '${login}' for linked server '${linkedServer}'?
   	            </Confirm>
               <Result>
   	               Login '${login}' was dropped for linked server '${linkedServer}'?
               </Result>
              </Action>
           </ActionGroup>
         </If>
         <Else>
            <Action id="sqlserver-linkedserver-INFO" label="Linked Server">
               <Confirm>
                  <![CDATA[
                  This feature is available only in the <b>DbVisualizer Pro</b> edition.
                  ]]>
               </Confirm>
            </Action>
         </Else>         
      </ActionGroup>

      <ActionGroup type="LinkedServers">
         <If test="#util.isLicensed()">
            <Action id="sqlserver-linkedserver-create" label="Create Linked Server" reload="true" icon="add">
                <Message type="info">For details about the various options, please refer to Microsoft's documentation on Stored Procedures for Distributed Queries.</Message>
	            <Input label="Server Name" name="linkedServerName" style="text" tip="Name of server. Example: 'SRVR002\ACCTG'"/>
	            <Input label="Product" name="linkedServerProduct" style="text" editable="true" tip="Product name of the OLE DB data source. If 'SQL Server', no other parameters (except server name) have to be specified." >
	               <Default>SQL Server</Default>
	            </Input>
               <Input label="Provider" name="linkedServerProvider" style="list" editable="true" tip="Unique identifier (PROGID) of the OLE DB provider.">
                  <Labels column="3">
                     <Command idref="sqlserver.getOleDbProviders" />
                  </Labels>
                  <Values column="1">
                     <Command idref="sqlserver.getOleDbProviders" />
                  </Values>
                </Input>
 	            <Input label="Data Source" name="linkedServerDataSource" style="text" tip="Data source (DBPROP_INIT_DATASOURCE) as interpreted by the OLE DB provider." />
	            <Input label="Location" name="linkedServerLocation" style="text" tip="Location (DBPROP_INIT_LOCATION) of the database as interpreted by the OLE DB provider."/>
	            <Input label="Provider String" name="linkedServerProviderString" style="text" tip="Provider-specific connection string (DBPROP_INIT_PROVIDERSTRING) to identify a unique data source."/>
	            <Input label="Catalog" name="linkedServerCatalog" style="text" tip="Catalog (DBPROP_INIT_CATALOG) to use  when connecting to the OLE DB provider."/>
                <!-- Wrap complete arguments (,@key='value') to omit blank fields -->
                <SetVar name="_provider" value='#linkedServerProvider.trim().equals("") ? "" : ", @provider = N&apos;${linkedServerProvider}&apos;"'/> 
                <SetVar name="_datasrc" value='#linkedServerDataSource.trim().equals("") ? "" : ", @datasrc = N&apos;${linkedServerDataSource}&apos;"'/> 
                <SetVar name="_location" value='#linkedServerLocation.trim().equals("") ? "" : ", @location = N&apos;${linkedServerLocation}&apos;"'/> 
                <SetVar name="_catalog" value='#linkedServerCatalog.trim().equals("") ? "" : ", @catalog = N&apos;${linkedServerCatalog}&apos;"'/> 
                <SetVar name="_provstr" value='#linkedServerProviderString.trim().equals("") ? "" : ", @provstr = N&apos;${linkedServerproviderString}&apos;"'/>
	            <Command>
	               <SQL>
	                  <![CDATA[
                     EXEC sp_addlinkedserver @server = N'${linkedServerName}', @srvproduct = N'${linkedServerProduct}'${_provider}${_datasrc}${_location}${_provstr}${_catalog};
                     ]]>
	               </SQL>
	            </Command>
	            <Confirm>
	               Confirm creation of linked server '${linkedServerName}'?
	            </Confirm>
	            <Result>
	               Linked server '${linkedServerName}' created!
	            </Result>
             </Action>
         </If>
         <Else>
            <Action id="sqlserver-linkedserver-create-INFO" label="Create Linked Server" icon="add" >
               <Confirm>
                  <![CDATA[
                  This feature is available only in the <b>DbVisualizer Pro</b> edition.
                  ]]>
               </Confirm>
            </Action>
         </Else>         
      </ActionGroup>
   </ObjectsActionDef>

   <!-- =================================================================== -->
   <!-- Definition of the database objects tree structure -->
   <!-- =================================================================== -->

   <ObjectsTreeDef extends="false">

      <GroupNode type="Catalogs" label="Databases">
         <DataNode type="Catalog" label="${getCatalogs.TABLE_CAT}">
            <SetVar name="catalog" value="${getCatalogs.TABLE_CAT}"/>
            <Command idref="getCatalogs">
               <Filter index="TABLE_CAT" label="Name"/>
            </Command>

            <GroupNode type="Schemas" label="Schemas">
               <DataNode type="Schema" label="${sqlserver.getSchemas.TABLE_SCHEM}">
                  <SetVar name="schema" value="${sqlserver.getSchemas.TABLE_SCHEM}"/>
                  <Command idref="sqlserver.getSchemas">
                     <Input name="catalog" value="${catalog}"/>
                     <Filter index="TABLE_SCHEM" label="Name"/>
                  </Command>

                  <GroupNode type="Tables" label="Tables">
                     <DataNode type="Table" label="${sqlserver.getObjects.name}">
                        <SetVar name="objectname" value="${sqlserver.getObjects.name}"/>
                        <SetVar name="rowcount" value="true"/>
                        <SetVar name="acceptInQB" value="true"/>
                        <Command idref="sqlserver.getObjects">
                           <Input name="database" value="${catalog}"/>
                           <Input name="schema" value="${schema}"/>
                           <Input name="type" value="'U'"/>
                        </Command>

                        <!--
                        Need to keep the objectname for the current table in
                        a new variable so that the viewers will be able to pick up
                        the correct input to display
                        -->

                        <SetVar name="theTableName" value="${objectname}"/>

                        <!-- 
                           The object type below is used to being able to distinguish 
                           Views from tables when editing managing extended properties for
                           view columns.
                         -->

                        <!-- Set the level 1 object type for Extended Properties -->
                        <SetVar name="extPropType1" value="N'Table'"/>
                        <SetVar name="extPropVal1" value="N'${objectname}'"/>
                        <SetVar name="extPropType2" value="Null"/>
                        <SetVar name="extPropVal2" value="Null"/>

                        <GroupNode type="Columns" label="Columns">
                           <DataNode type="Column" label="${getColumnDefinitions.COLUMN_NAME}"
                                     label1="${getColumnDefinitions.TYPE_NAME}" isLeaf="true"
                                     icon="#dataMap.get('getColumnDefinitions.IS_PRIMARY_KEY') eq true ? 'PrimaryKey' : 'Column'"
                                     tip="#dataMap.get('getColumnDefinitions.IS_PRIMARY_KEY') eq true ? 'This is a primary key column' : ''">
                              <SetVar name="objectname" value="${getColumnDefinitions.COLUMN_NAME}"/>
                              <Command idref="getColumnDefinitions">
                                 <Input name="catalog" value="${catalog}"/>
                                 <Input name="schema" value="${schema}"/>
                                 <Input name="objectname" value="${theTableName}"/>
                                 <Input name="tableType" value="Table"/>
                                 <Filter index="TYPE_NAME" label="Type"/>
                              </Command>
                              <SetVar name="extPropType2" value="N'column'"/>
                              <SetVar name="extPropVal2" value="N'${objectname}'"/>
                           </DataNode>
                        </GroupNode>

                        <GroupNode type="Indexes" label="Indexes">
                           <DataNode type="Index" label="${sqlserver.getIndexes.INDEX_NAME} (${sqlserver.getIndexes.OWNER}.${sqlserver.getIndexes.TABLE_NAME})"
                                     isLeaf="true">
                              <SetVar name="objectname" value="${sqlserver.getIndexes.INDEX_NAME}"/>
                              <SetVar name="getDDLName" value="${sqlserver.getIndexes.TABLE_NAME}/${sqlserver.getIndexes.INDEX_NAME}"/>
                              <Command idref="sqlserver.getIndexes">
                                 <Input name="database" value="${catalog}"/>
                                 <Input name="schema" value="${schema}"/>
                                 <Input name="table" value="${theTableName}"/>
                                 <ProcessDataSet action="removeisnullrows" index="INDEX_NAME"/>
                              </Command>
                           </DataNode>
                        </GroupNode>

                        <GroupNode type="Triggers" label="Triggers">
                           <DataNode type="Trigger" label="${sqlserver.getTableTriggers.trigger_name}"
                                     label1="${sqlserver.getTableTriggers.table_name}"
                                     isLeaf="true"
                                     warnstate="#dataMap.get('sqlserver.getTableTriggers.is_disabled').equals(true)"
                                     tip="#dataMap.get('sqlserver.getTableTriggers.is_disabled').equals(true) ? 'Trigger is disabled' : ''">
                              <SetVar name="schema" value="${sqlserver.getTableTriggers.trigger_owner}"/>
                              <SetVar name="objectname" value="${sqlserver.getTableTriggers.trigger_name}"/>
                              <SetVar name="table_owner" value="${sqlserver.getTableTriggers.table_owner}"/>
                              <SetVar name="table_name" value="${sqlserver.getTableTriggers.table_name}"/>
                              <Command idref="sqlserver.getTableTriggers">
                                 <Input name="database" value="${catalog}"/>
                                 <Input name="owner" value="${schema}"/>
                                 <Input name="name" value="${theTableName}"/>
                                 <Filter index="table_name" label="Table Name"/>
                              </Command>
                           </DataNode>
                        </GroupNode>
                     </DataNode>
                  </GroupNode>

                  <GroupNode type="Views" label="Views">
                     <DataNode type="View" label="${sqlserver.getObjects.name}">
                        <SetVar name="schema" value="${sqlserver.getObjects.owner}"/>
                        <SetVar name="objectname" value="${sqlserver.getObjects.name}"/>
                        <SetVar name="rowcount" value="true"/>
                        <SetVar name="acceptInQB" value="true"/>
                        <Command idref="sqlserver.getObjects">
                           <Input name="database" value="${catalog}"/>
                           <Input name="schema" value="${schema}"/>
                           <Input name="type" value="'V'"/>
                        </Command>

                        <!--
                        Need to keep the objectname for the current table in
                        a new variable so that the viewers will be able to pick up
                        the correct input to display
                        -->
                        <SetVar name="theTableName" value="${objectname}"/>

                        <SetVar name="extPropType1" value="N'View'"/>
                        <SetVar name="extPropVal1" value="N'${objectname}'"/>
                        <SetVar name="extPropType2" value="Null"/>
                        <SetVar name="extPropVal2" value="Null"/>
                        
                        <GroupNode type="Columns" label="Columns">
                           <DataNode type="Column" label="${getColumnDefinitions.COLUMN_NAME}"
                                     label1="${getColumnDefinitions.TYPE_NAME}" isLeaf="true">
                              <SetVar name="objectname" value="${getColumnDefinitions.COLUMN_NAME}"/>
                              <Command idref="getColumnDefinitions">
                                 <Input name="catalog" value="${catalog}"/>
                                 <Input name="schema" value="${schema}"/>
                                 <Input name="objectname" value="${theTableName}"/>
                                 <Input name="tableType" value="View"/>
                                 <Filter index="TYPE_NAME" label="Type"/>
                              </Command>
                              <SetVar name="extPropType2" value="N'column'"/>
                              <SetVar name="extPropVal2" value="N'${objectname}'"/>
                           </DataNode>
                        </GroupNode>

                        <GroupNode type="Triggers" label="Triggers">
                           <DataNode type="Trigger" label="${sqlserver.getTriggers.trigger_name}"
                                     label1="${sqlserver.getTriggers.table_name}"
                                     isLeaf="true"
                                     warnstate="#dataMap.get('sqlserver.getTriggers.is_disabled').equals(true)"
                                     tip="#dataMap.get('sqlserver.getTriggers.is_disabled').equals(true) ? 'Trigger is disabled' : ''">
                              <SetVar name="schema" value="${sqlserver.getTriggers.trigger_owner}"/>
                              <SetVar name="objectname" value="${sqlserver.getTriggers.trigger_name}"/>
                              <SetVar name="table_owner" value="${sqlserver.getTriggers.table_owner}"/>
                              <SetVar name="table_name" value="${sqlserver.getTriggers.table_name}"/>
                              <Command idref="sqlserver.getTriggers">
                                 <Input name="database" value="${catalog}"/>
                                 <Input name="schema" value="${schema}"/>
                                 <Input name="tableNamePattern" value="${theTableName}"/>
                                 <Filter index="table_name" label="Table Name"/>
                              </Command>
                           </DataNode>
                        </GroupNode>
                     </DataNode>
                  </GroupNode>

                  <GroupNode type="Synonyms" label="Synonyms">
                     <DataNode type="Synonym" label="${sqlserver.getSynonyms.name}" isLeaf="true">
                        <SetVar name="schema" value="${sqlserver.getSynonyms.owner}"/>
                        <SetVar name="objectname" value="${sqlserver.getSynonyms.name}"/>
                        <SetVar name="rowcount" value="true"/>
                        <Command idref="sqlserver.getSynonyms">
                           <Input name="database" value="${catalog}"/>
                           <Input name="schema" value="${schema}"/>
                        </Command>
                     </DataNode>
                  </GroupNode>

                  <SetVar name="theTableName" value="%"/>

                  <GroupNode type="Indexes" label="Indexes">
                     <DataNode type="Index" label="${sqlserver.getIndexes.INDEX_NAME} (${sqlserver.getIndexes.OWNER}.${sqlserver.getIndexes.TABLE_NAME})"
                               isLeaf="true">
                        <SetVar name="schema" value="${sqlserver.getIndexes.OWNER}"/>
                        <SetVar name="objectname" value="${sqlserver.getIndexes.INDEX_NAME}"/>
                        <SetVar name="getDDLName" value="${sqlserver.getIndexes.TABLE_NAME}/${sqlserver.getIndexes.INDEX_NAME}"/>
                        <Command idref="sqlserver.getIndexes">
                           <Input name="database" value="${catalog}"/>
                           <Input name="schema" value="${schema}"/>
                           <Input name="table" value="%"/>
                           <Filter index="OWNER" label="Owner"/>
                           <Filter index="TABLE_NAME" label="Table Name"/>
                        </Command>
                     </DataNode>
                  </GroupNode>

                  <If test="#util.isDatabaseVersionGTE(11)">
                     <GroupNode type="Sequences" label="Sequences">
                        <DataNode type="Sequence" label="${sqlserver.getSequences.SEQUENCE_NAME}"
                                  label1="${sqlserver.getSequences.DATA_TYPE}"
                                  isLeaf="true">
                           <SetVar name="objectname" value="${sqlserver.getSequences.SEQUENCE_NAME}"/>
                           <Command idref="sqlserver.getSequences">
                              <Input name="database" value="${catalog}"/>
                              <Input name="schema" value="${schema}"/>
                              <Input name="table" value="%"/>
                           </Command>
                        </DataNode>
                     </GroupNode>
                  </If>

                  <GroupNode type="Types" label="User Defined Data Types" isLeaf="true"/>

                  <SetVar name="theTableName" value="%"/>

                  <GroupNode type="Triggers" label="Triggers">
                     <DataNode type="Trigger" label="${sqlserver.getTriggers.trigger_name}"
                               label1="${sqlserver.getTriggers.table_owner}.${sqlserver.getTriggers.table_name}"
                               isLeaf="true"
                               warnstate="#dataMap.get('sqlserver.getTriggers.is_disabled').equals(true)"
                               tip="#dataMap.get('sqlserver.getTriggers.is_disabled').equals(true) ? 'Trigger is disabled' : ''">
                        <SetVar name="objectname" value="${sqlserver.getTriggers.trigger_name}"/>
                        <SetVar name="table_owner" value="${sqlserver.getTriggers.table_owner}"/>
                        <SetVar name="table_name" value="${sqlserver.getTriggers.table_name}"/>
                        <Command idref="sqlserver.getTriggers">
                           <Input name="database" value="${catalog}"/>
                           <Input name="schema" value="${schema}"/>
                           <Input name="tableNamePattern" value="${theTableName}"/>
                           <Filter index="table_owner" label="Owner"/>
                           <Filter index="table_name" label="Table Name"/>
                        </Command>
                     </DataNode>
                  </GroupNode>

                  <GroupNode type="Procedures" label="Stored Procedures">
                     <DataNode type="Procedure" label="${sqlserver.getObjects.name}" isLeaf="true">
                        <SetVar name="objectname" value="${sqlserver.getObjects.name}"/>
                        <Command idref="sqlserver.getObjects">
                           <Input name="database" value="${catalog}"/>
                           <Input name="schema" value="${schema}"/>
                           <Input name="type" value="'P'"/>
                        </Command>
                     </DataNode>
                  </GroupNode>

                  <GroupNode type="Functions" label="Functions">
                     <DataNode type="Function" label="${sqlserver.getObjects.name}" isLeaf="true">
                        <SetVar name="objectname" value="${sqlserver.getObjects.name}"/>
                        <Command idref="sqlserver.getObjects">
                           <Input name="database" value="${catalog}"/>
                           <Input name="schema" value="${schema}"/>
                           <Input name="type" value="'FN', 'IF', 'TF'"/>
                        </Command>
                     </DataNode>
                  </GroupNode>
               </DataNode>
            </GroupNode>

            <If test="#SQL_SERVER_EDITION neq 'Azure'">
               <GroupNode type="Users" label="Users" isLeaf="true"/>
            </If>

            <GroupNode type="Roles" label="Database Roles">
               <DataNode type="Role" label="${sqlserver.getRoles.RoleName}" isLeaf="true">
                  <SetVar name="objectname" value="${sqlserver.getRoles.RoleName}"/>
                  <Command idref="sqlserver.getRoles">
                     <Input name="database" value="${catalog}"/>
                  </Command>
               </DataNode>
            </GroupNode>

         </DataNode>
      </GroupNode>

      <!-- ================================================================= -->
      <!-- Linked Servers													 -->
      <!-- ================================================================= -->
	  
	  <!-- Linked Servers were introduced in SQL Server 2008 -->
      <If test="#util.isDatabaseVersionGTE(10) and #IS_LINKED_SERVERS_SUPPORTED eq 'true'">
         <GroupNode type="LinkedServers" label="Linked Servers">
            <DataNode type="LinkedServer" label="${sqlserver.getLinkedServers.name}">
               <SetVar name="linkedServer" value="${sqlserver.getLinkedServers.name}" />
               <Command idref="sqlserver.getLinkedServers" />
	
               <GroupNode type="LinkedServerCatalogs" label="Databases">
                  <DataNode type="LinkedServerCatalog" label="${sqlserver.getLinkedCatalogs.CATALOG_NAME}">
                     <SetVar name="linkedCatalog" value="${sqlserver.getLinkedCatalogs.CATALOG_NAME}" />
                     <Command idref="sqlserver.getLinkedCatalogs">
                        <Input name="linkedServer" value="${linkedServer}" />
                     </Command>
	
                     <GroupNode type="LinkedServerSchemas" label="Schemas">
                        <DataNode type="LinkedServerSchema" label="${sqlserver.getLinkedSchemas.TABLE_SCHEM}">
                           <SetVar name="linkedSchema" value="${sqlserver.getLinkedSchemas.TABLE_SCHEM}" />
                           <Command idref="sqlserver.getLinkedSchemas">
                              <Input name="linkedServer" value="${linkedServer}" />
                              <Input name="linkedCatalog" value="${linkedCatalog}" />
                           </Command>
	
                           <GroupNode type="LinkedServerTables" label="Tables">
                              <DataNode type="LinkedServerTable" label="${sqlserver.getLinkedTables.TABLE_NAME}">
                                 <SetVar name="linkedTable" value="${sqlserver.getLinkedTables.TABLE_NAME}" />
                                 <SetVar name="objectname" value="${linkedTable}"/> <!-- objectname is used by general viewers -->
                                 <Command idref="sqlserver.getLinkedTables">
                                    <Input name="linkedServer" value="${linkedServer}" />
                                    <Input name="linkedCatalog" value="${linkedCatalog}" />
                                    <Input name="linkedSchema" value="${linkedSchema}" />
                                    <Input name="linkedTable" value="${linkedTable}" />
                                 </Command>
	
                                 <GroupNode type="LinkedServerColumns" label="Columns" >
                                    <DataNode type="LinkedServerColumn" label="${sqlserver.getLinkedTableColumns.COLUMN_NAME}"  label1="${sqlserver.getLinkedTableColumns.TYPE_NAME}"  isLeaf="true">
                                       <SetVar name="linkedColumn" value="${sqlserver.getLinkedTableColumns.COLUMN_NAME}" />
                                       <Command idref="sqlserver.getLinkedTableColumns">
                                          <Input name="linkedServer" value="${linkedServer}" />
                                          <Input name="linkedCatalog" value="${linkedCatalog}" />
                                          <Input name="linkedSchema" value="${linkedSchema}" />
                                          <Input name="linkedTable" value="${linkedTable}" />
                                       </Command>
                                    </DataNode>
                                 </GroupNode>
<!-- sp_indexes doesn't work
										<GroupNode type="LinkedServerIndexes" label="Indexes">
											<DataNode type="LinkedServerIndex" label="${sqlserver.getLinkedTableIndexes.INDEX_NAME}">
												<SetVar name="linkedIndex" value="${sqlserver.getLinkedTableIndexes.INDEX_NAME}" />
												<Command idref="sqlserver.getLinkedTableIndexes">
													<Input name="linkedServer" value="${linkedServer}" />
													<Input name="linkedCatalog" value="${linkedCatalog}" />
													<Input name="linkedSchema" value="${linkedSchema}" />
													<Input name="linkedTable" value="${linkedTable}" />
												</Command>
											</DataNode>
										</GroupNode>
-->
                              </DataNode>
                           </GroupNode>
	
                           <GroupNode type="LinkedServerViews" label="Views">
                              <DataNode type="LinkedServerView" label="${sqlserver.getLinkedViews.TABLE_NAME}">
                                 <SetVar name="linkedTable" value="${sqlserver.getLinkedViews.TABLE_NAME}" />
                                 <Command idref="sqlserver.getLinkedViews">
                                    <Input name="linkedServer" value="${linkedServer}" />
                                    <Input name="linkedCatalog" value="${linkedCatalog}" />
                                    <Input name="linkedSchema" value="${linkedSchema}" />
                                 </Command>
                                 <GroupNode type="LinkedServerColumns" label="Columns" >
                                    <DataNode type="LinkedServerColumn" label="${sqlserver.getLinkedTableColumns.COLUMN_NAME}"  label1="${sqlserver.getLinkedTableColumns.TYPE_NAME}"  isLeaf="true">
                                       <SetVar name="linkedColumn" value="${sqlserver.getLinkedTableColumns.COLUMN_NAME}" />
                                       <Command idref="sqlserver.getLinkedTableColumns">
                                          <Input name="linkedServer" value="${linkedServer}" />
                                          <Input name="linkedCatalog" value="${linkedCatalog}" />
                                          <Input name="linkedSchema" value="${linkedSchema}" />
                                          <Input name="linkedTable" value="${linkedTable}" />
                                       </Command>
                                    </DataNode>
                                 </GroupNode>
                              </DataNode>
                           </GroupNode>
	
<!-- sp_indexes doesn't work 									
								<GroupNode type="LinkedServerIndexes" label="Indexes">
									<DataNode type="LinkedServerIndex" label="${sqlserver.getLinkedIndexes.INDEX_NAME}">
										<Command idref="sqlserver.getLinkedIndexes">
											<Input name="linkedServer" value="${linkedServer}" />
											<Input name="linkedCatalog" value="${linkedCatalog}" />
											<Input name="linkedSchema" value="${linkedSchema}" />
										</Command>
									</DataNode>
								</GroupNode>
-->									
                           <GroupNode type="LinkedServerSynonyms" label="Synonyms">
                              <DataNode type="LinkedServerSynonym" label="${sqlserver.getLinkedSynonyms.TABLE_NAME}" isLeaf="true" >
                                 <SetVar name="linkedSynonym" value="${sqlserver.getLinkedSynonyms.TABLE_NAME}" />
                                 <Command idref="sqlserver.getLinkedSynonyms">
                                    <Input name="linkedServer" value="${linkedServer}" />
                                    <Input name="linkedCatalog" value="${linkedCatalog}" />
                                    <Input name="linkedSchema" value="${linkedSchema}" />
                                    <Input name="linkedSynonym" value="${linkedSynonym}" />
                                 </Command>
                              </DataNode>
                           </GroupNode>
								
                        </DataNode>
                     </GroupNode>
                  </DataNode>
               </GroupNode>
            </DataNode>
         </GroupNode>
      </If>
	
      <!-- ================================================================= -->
      <!-- DBA Nodes -->
      <!-- ================================================================= -->

      <GroupNode type="DBA" label="DBA Views">
         <GroupNode type="ServerInfo" label="Server Info" isLeaf="true"/>

         <If test="#SQL_SERVER_EDITION neq 'Azure'">
            <GroupNode type="Logins" label="Logins" isLeaf="true"/>
         </If>

         <If test="#SQL_SERVER_EDITION neq 'Azure'">
            <GroupNode type="Devices" label="Database Devices" isLeaf="true"/>
         </If>

         <If test="#SQL_SERVER_EDITION neq 'Azure'">
            <GroupNode type="Processes" label="Processes" isLeaf="true"/>
         </If>

         <If test="#SQL_SERVER_EDITION neq 'Azure'">
            <GroupNode type="ServerRoles" label="Server Roles" isLeaf="false">
               <DataNode type="ServerRole" label="${sqlserver.getServerRoles.ServerRole}" isLeaf="true">
                  <SetVar name="objectname" value="${sqlserver.getServerRoles.ServerRole}"/>
                  <Command idref="sqlserver.getServerRoles">
                     <Input name="database" value="${catalog}"/>
                  </Command>
               </DataNode>
            </GroupNode>
         </If>

         <If test="#util.isDatabaseVersionGTE(9) and #SQL_SERVER_EDITION neq 'Azure'">
            <GroupNode type="ServerAgent" label="SQL Server Agent" isLeaf="false">

               <!-- ServerAgent/Jobs -->
               <GroupNode type="Jobs" label="Agent Jobs" isLeaf="false">
                  <!-- ServerAgent/Jobs/job-x -->
                  <DataNode type="Job" label="${sqlserver.getAgentJobs.JobName}" isLeaf="false"
                            label1="${sqlserver.getAgentJobs.IsDisabledText}"
                            warnstate="'Retry'.equals(#dataMap.get('sqlserver.getAgentJobs.LastRunStatus'))"
                            errorstate="'Failed'.equals(#dataMap.get('sqlserver.getAgentJobs.LastRunStatus'))"
                            tip="'Retry'.equals(#dataMap.get('sqlserver.getAgentJobs.LastRunStatus')) or 'Failed'.equals(#dataMap.get('sqlserver.getAgentJobs.LastRunStatus')) ? 'Agent job is in a retry or failed state' : ''">
                     <SetVar name="objectname" value="${sqlserver.getAgentJobs.JobName}"/>
                     <SetVar name="theJobName" value="${sqlserver.getAgentJobs.JobName}"/>

                     <Command idref="sqlserver.getAgentJobs">
                        <Input name="jobCondition" value=""/>
                     </Command>

                     <DataNode type="JobStep" label="${sqlserver.getAgentJobSteps.step_name}"
                               label1="${sqlserver.getAgentJobSteps.step_id}"
                               isLeaf="true">
                        <SetVar name="objectname" value="${sqlserver.getAgentJobSteps.step_name}"/>
                        <SetVar name="jobStepID" value="${sqlserver.getAgentJobSteps.step_id}"/>
                        <SetVar name="jobStepCommand" value="${sqlserver.getAgentJobSteps.command}"/>
                        <Command idref="sqlserver.getAgentJobSteps">
                           <!--    E.g jobStepCondition =  "where job_id = '${job_id}'" -->
                           <Input name="jobStepCondition" value="where job_id = '${sqlserver.getAgentJobs.JobID}'"/>
                        </Command>
                     </DataNode>

                     <!-- ServerAgent/Jobs/Schedules -->
                     <GroupNode type="JobSchedules" label="Schedules">
                        <!-- ServerAgent/Jobs/Schedules/Schedule-x -->
                        <DataNode type="JobSchedule" label="${sqlserver.getAgentJobSchedules.ScheduleName}" isLeaf="true"
                                  label1="${sqlserver.getAgentJobSchedules.IsDisabledText}">
                           <SetVar name="objectname" value="${sqlserver.getAgentJobSchedules.ScheduleName}"/>
                           <SetVar name="scheduleID" value="${sqlserver.getAgentJobSchedules.ScheduleID}"/>
                           <Command idref="sqlserver.getAgentJobSchedules">
                              <Input name="condition" value="INNER JOIN msdb.dbo.sysjobschedules ON msdb.dbo.sysjobschedules.schedule_id = msdb.dbo.sysschedules.schedule_id
where  msdb.dbo.sysjobschedules.job_id = '{${sqlserver.getAgentJobs.JobID}}'"/>
                           </Command>

                        </DataNode>
                     </GroupNode>

                     <!-- ServerAgent/Jobs/Targets -->
                     <GroupNode type="JobServers" label="Targets">
                        <!-- ServerAgent/Jobs/Targets/Target-X -->
                        <DataNode type="JobServer" label="${sqlserver.getAgentJobServers.server_name}" isLeaf="true">
                           <SetVar name="objectname" value="${sqlserver.getAgentJobServers.server_name}"/>
                           <Command idref="sqlserver.getAgentJobServers">
                              <Input name="jobName" value="${theJobName}"/>
                           </Command>
                        </DataNode>
                     </GroupNode>
                  </DataNode>
               </GroupNode>

               <GroupNode type="SchedulerSchedules" label="Schedules" isLeaf="false">
                  <DataNode type="SchedulerSchedule" label="${sqlserver.getAgentJobSchedules.ScheduleName}" isLeaf="true"
                            label1="${sqlserver.getAgentJobSchedules.IsDisabledText}">
                     <SetVar name="objectname" value="${sqlserver.getAgentJobSchedules.ScheduleName}"/>
                     <SetVar name="scheduleID" value="${sqlserver.getAgentJobSchedules.ScheduleID}"/>
                     <Command idref="sqlserver.getAgentJobSchedules">
                        <Input name="condition" value=""/>
                     </Command>
                  </DataNode>
               </GroupNode>

               <GroupNode type="Alerts" label="Alerts" isLeaf="false">
                  <DataNode type="Alert" label="${sqlserver.getAgentAlerts.name}" isLeaf="true">
                     <SetVar name="objectname" value="${sqlserver.getAgentAlerts.name}"/>
                     <Command idref="sqlserver.getAgentAlerts">
                        <Input name="condition" value=""/>
                     </Command>
                  </DataNode>
               </GroupNode>

               <GroupNode type="Operators" label="Operators" isLeaf="false">
                  <DataNode type="Operator" label="${sqlserver.getAgentOperators.name}" isLeaf="true">
                     <SetVar name="objectname" value="${sqlserver.getAgentOperators.name}"/>
                     <Command idref="sqlserver.getAgentOperators">
                        <Input name="condition" value=""/>
                     </Command>
                  </DataNode>
               </GroupNode>

            </GroupNode>
         </If>

         <If test="#SQL_SERVER_EDITION neq 'Azure'">
            <GroupNode type="Locks" label="Locks" isLeaf="true"/>
         </If>

      </GroupNode>

   </ObjectsTreeDef>

   <!-- =================================================================== -->
   <!-- Definition of the database objects views -->
   <!-- =================================================================== -->

   <ObjectsViewDef extends="true">

      <ObjectView type="Catalog" action="drop"/>
      
      <ObjectView type="Schemas">
         <DataView id="generic-schemas-schemas" action="drop"/>

         <DataView id="sqlserver-schemas-schemas" icon="Schemas" label="Schemas" viewer="grid">
            <Command idref="sqlserver.getSchemas">
               <Input name="catalog" value="${catalog}"/>
            </Command>
         </DataView>
      </ObjectView>

      <ObjectView type="Schema" action="drop"/>

      <ObjectView type="Tables">
         <DataView id="generic-tables-tables" action="drop"/>
         <DataView id="generic-tables-references" action="drop"/>

         <DataView id="sqlserver-tables-tables" icon="Tables" label="Tables" viewer="grid">
            <Input name="menuItem" value="Open in New Tab...">
               <Input name="action" value="open-object-in-new-tab-command ${schema||TABLE_SCHEM}${object||TABLE_NAME}"/>
            </Input>
            <Input name="menuItem" value="Open in Floating Tab...">
               <Input name="action" value="open-object-in-floating-tab-command ${schema||TABLE_SCHEM}${object||TABLE_NAME}"/>
            </Input>
            <Input name="menuItem" value="Script: SELECT ALL">
               <Input name="command" value="select * from ${schema||TABLE_SCHEM}${object||TABLE_NAME}"/>
            </Input>
            <Input name="menuItem" value="Script: DROP TABLE">
               <Input name="command" value="drop table ${schema||TABLE_SCHEM}${object||TABLE_NAME}"/>
            </Input>
            <Command idref="sqlserver.getObjects">
                <Input name="database" value="${catalog}"/>
                <Input name="schema" value="${schema}"/>
                <Input name="type" value="'U'"/>
            </Command>
         </DataView>
         <DataView id="sqlserver-tables-references" icon="References" label="References" viewer="tables-refs"
                   doclink="http://www.dbvis.com/doclink/show-references">
            <Command idref="getTables">
               <Input name="catalog" value="${catalog}"/>
               <Input name="schema" value="${schema}"/>
               <Input name="objectname" value="%"/>
               <Input name="tableType" value="TABLE"/>
            </Command>
         </DataView>
      </ObjectView>

      <ObjectView type="Table">
         <DataView id="generic-table-ddl" action="drop"/>
         <DataView id="generic-table-indexes" action="drop"/>
         
         <If test="#util.isDatabaseVersionGT(9)">
            <DataView id="sqlserver-table-indexes" icon="Index" label="Indexes" viewer="grid">
               <Command idref="sqlserver.getTableIndexes">
                  <Input name="owner" value="${schema}"/>
                  <Input name="name" value="${objectname}"/>
               </Command>
            </DataView>
         </If>  
         <Else>
           <DataView id="sqlserver-table-indexes-driver" icon="Index" label="Indexes" viewer="grid">
              <Command idref="getIndexes">
                <Input name="catalog" value="${catalog}"/>
                <Input name="schema" value="${schema}"/>
                <Input name="objectname" value="${objectname}"/>
             </Command>
           </DataView>
         </Else>
     
         <DataView id="sqlserver-table-ddl" icon="Source" label="DDL" viewer="ddl">
            <Input name="formatSQL" value="true"/>
         </DataView>

         <DataView id="sqlserver-table-triggers" icon="Trigger" label="Triggers" viewer="form">
            <Command idref="sqlserver.getTableTriggers">
               <Input name="database" value="${catalog}"/>
               <Input name="owner" value="${schema}"/>
               <Input name="name" value="${objectname}"/>
            </Command>
         </DataView>
         <DataView id="sqlserver-table-props-table" icon="ExtendedProp" label="Extended Properties" viewer="grid">
            <Command idref="sqlserver.getExtendedProp">
               <Input name="objectNameLabel" value="Table Name"/>
               <Input name="prop_name" value="Null"/>
               <Input name="lev0_type" value="N'schema'"/>
               <Input name="lev0_val" value="N'${schema}'"/>
               <Input name="lev1_type" value="${extPropType1}"/>
               <Input name="lev1_val" value="${extPropVal1}"/>
               <Input name="lev2_type" value="${extPropType2}"/>
               <Input name="lev2_val" value="${extPropVal2}"/>
               <ProcessDataSet action="dropcolumn" index="Table Name"/>
            </Command>
         </DataView>
      </ObjectView>

      <ObjectView type="Columns">
         <DataView id="sqlserver-extended-props-columns" icon="ExtendedProp" label="Extended Properties" viewer="grid">
            <Command idref="sqlserver.getExtendedProp">
               <Input name="objectNameLabel" value="Column Name"/>
               <Input name="prop_name" value="Null"/>
               <Input name="lev0_type" value="N'schema'"/>
               <Input name="lev0_val" value="N'${schema}'"/>
               <Input name="lev1_type" value="${extPropType1}"/>
               <Input name="lev1_val" value="${extPropVal1}"/>
               <Input name="lev2_type" value="N'column'"/>
               <Input name="lev2_val" value="Null"/>
            </Command>
         </DataView>
      </ObjectView>
      <ObjectView type="Column">
         <DataView id="sqlserver-extended-props-column" icon="ExtendedProp" label="Extended Properties" viewer="grid">
            <Command idref="sqlserver.getExtendedProp">
               <Input name="objectNameLabel" value="Column Name"/>
               <Input name="prop_name" value="Null"/>
               <Input name="lev0_type" value="N'schema'"/>
               <Input name="lev0_val" value="N'${schema}'"/>
               <Input name="lev1_type" value="${extPropType1}"/>
               <Input name="lev1_val" value="${extPropVal1}"/>
               <Input name="lev2_type" value="${extPropType2}"/>
               <Input name="lev2_val" value="${extPropVal2}"/>
               <ProcessDataSet action="dropcolumn" index="Column Name"/>
            </Command>
         </DataView>
      </ObjectView>
      <ObjectView type="Views">
         <DataView id="sqlserver-views-views" icon="Views" label="Views" viewer="grid">
            <Input name="menuItem" value="Open in New Tab...">
               <Input name="action" value="open-object-in-new-tab-command ${schema||TABLE_SCHEM}${object||TABLE_NAME}"/>
            </Input>
            <Input name="menuItem" value="Open in Floating Tab...">
               <Input name="action" value="open-object-in-floating-tab-command ${schema||TABLE_SCHEM}${object||TABLE_NAME}"/>
            </Input>
            <Input name="menuItem" value="Script: SELECT ALL">
               <Input name="command" value="select * from ${schema||TABLE_SCHEM}${object||TABLE_NAME}"/>
            </Input>
            <Input name="menuItem" value="Script: DROP VIEW">
               <Input name="command" value="drop view ${schema||TABLE_SCHEM}${object||TABLE_NAME}"/>
            </Input>
             <Command idref="sqlserver.getObjects">
                <Input name="database" value="${catalog}"/>
                <Input name="schema" value="${schema}"/>
                <Input name="type" value="'V'"/>
            </Command>
         </DataView>
      </ObjectView>

      <ObjectView type="View">
         <DataView id="sqlserver-view-info" icon="Info" label="Info" viewer="node-form"/>
         <DataView id="sqlserver-view-columns" icon="Columns" label="Columns" viewer="grid">
            <Command idref="getColumns">
               <Input name="catalog" value="${catalog}"/>
               <Input name="schema" value="${schema}"/>
               <Input name="objectname" value="${objectname}"/>
            </Command>
         </DataView>
         <DataView id="sqlserver-view-data" icon="Data" label="Data" viewer="table-data"/>
         <DataView id="sqlserver-view-rowcount" icon="RowCount" label="Row Count" viewer="table-rowcount"/>
         <DataView id="sqlserver-view-indexes" icon="Index" label="Indexes" viewer="grid">
            <Command idref="getIndexes">
               <Input name="catalog" value="${catalog}"/>
               <Input name="schema" value="${schema}"/>
               <Input name="objectname" value="${objectname}"/>
            </Command>
         </DataView>
         <DataView id="sqlserver-view-ddl" icon="Source" label="DDL" viewer="ddl">
            <Input name="objectType" value="View"/>
            <Input name="formatSQL" value="true"/>
         </DataView>
         <DataView id="sqlserver-table-props-view" icon="ExtendedProp" label="Extended Properties" viewer="grid">
            <Command idref="sqlserver.getExtendedProp">
               <Input name="objectNameLabel" value="Table Name"/>
               <Input name="prop_name" value="Null"/>
               <Input name="lev0_type" value="N'schema'"/>
               <Input name="lev0_val" value="N'${schema}'"/>
               <Input name="lev1_type" value="${extPropType1}"/>
               <Input name="lev1_val" value="${extPropVal1}"/>
               <Input name="lev2_type" value="${extPropType2}"/>
               <Input name="lev2_val" value="${extPropVal2}"/>
               <ProcessDataSet action="dropcolumn" index="Table Name"/>
            </Command>
         </DataView>
      </ObjectView>

      <ObjectView type="Indexes">
         <DataView id="generic-indexes-indexes" action="drop"/>
         <DataView id="sqlserver-indexes-indexes" icon="Indexes" label="Indexes" viewer="grid">
            <Command idref="sqlserver.getIndexes">
               <Input name="database" value="${catalog}"/>
               <Input name="schema" value="${schema}"/>
               <Input name="table" value="${theTableName}"/>
            </Command>
         </DataView>
      </ObjectView>

      <ObjectView type="Index">
         <If test="#util.isDatabaseVersionGTE(9)">
            <DataView id="sqlserver-index-ddl" icon="Source" label="DDL" viewer="ddl">
               <Input name="objectType" value="Index"/>
               <Input name="formatSQL" value="true"/>
            </DataView>
         </If>
      </ObjectView>

      <ObjectView type="Sequences">
         <DataView id="sqlserver-sequences-sequences" icon="Sequences" label="Sequences" viewer="grid">
            <Command idref="sqlserver.getSequences">
               <Input name="database" value="${catalog}"/>
               <Input name="schema" value="${schema}"/>
            </Command>
            <Input name="menuItem" value="Script: DROP SEQUENCE">
               <Input name="command" value="drop sequence ${schema||SEQUENCE_SCHEMA}${object||SEQUENCE_NAME}"/>
            </Input>
         </DataView>
      </ObjectView>

      <ObjectView type="Sequence">
         <DataView id="sqlserver-sequence-info" icon="Info" label="Info" viewer="node-form"/>
      </ObjectView>

      <ObjectView type="Synonyms">
         <DataView id="sqlserver-synonyms-synonyms" icon="Synonyms" label="Synonyms" viewer="grid">
            <Command idref="sqlserver.getSynonyms">
               <Input name="database" value="${catalog}"/>
               <Input name="schema" value="${schema}"/>
            </Command>
         </DataView>
      </ObjectView>

      <ObjectView type="Synonym">
         <DataView id="sqlserver-synonym-info" icon="Info" label="Info" viewer="node-form"/>
      </ObjectView>

      <ObjectView type="Users">
         <DataView id="sqlserver-users-users" icon="Users" label="Users" viewer="grid">
            <Command idref="sqlserver.getUsers">
               <Input name="database" value="${catalog}"/>
            </Command>
         </DataView>
      </ObjectView>

      <ObjectView type="Roles">
         <DataView id="sqlserver-roles-roles" icon="Roles" label="Roles" viewer="grid">
            <Command idref="sqlserver.getRoles">
               <Input name="database" value="${catalog}"/>
            </Command>
         </DataView>
      </ObjectView>

      <ObjectView type="Role">
         <DataView id="sqlserver-role-info" icon="Info" label="Info" viewer="node-form"/>
         <If test="#SQL_SERVER_EDITION neq 'Azure'">
            <DataView id="sqlserver-role-users" icon="Users" label="Users" viewer="grid">
               <Command idref="sqlserver.getRoleMembers">
                  <Input name="database" value="${catalog}"/>
                  <Input name="name" value="${objectname}"/>
               </Command>
            </DataView>
         </If>
      </ObjectView>

      <ObjectView type="Triggers">
         <DataView id="sqlserver-triggers-triggers" icon="Triggers" label="Triggers" viewer="grid">
            <Command idref="sqlserver.getTriggers">
               <Input name="database" value="${catalog}"/>
               <Input name="schema" value="${schema}"/>
               <Input name="tableNamePattern" value="${theTableName}"/>
            </Command>
         </DataView>
      </ObjectView>

      <ObjectView type="Trigger">
         <DataView classargs="TRIGGER" id="sqlserver-trigger-triggereditor" icon="SourceEditor" label="Trigger Editor" viewer="ProcedureViewer"
                   doclink="http://www.dbvis.com/doclink/edit-code-object"/>
         <DataView id="sqlserver-trigger-info" icon="Info" label="Info" viewer="node-form"/>
         <!--
         <DataView type="Source" label="Source" viewer="text">
            <Input name="formatSQL" value="true"/>

            <Command idref="sqlserver.getObjectSource">
               <Input name="database" value="${catalog}"/>
               <Input name="owner" value="${schema}"/>
               <Input name="name" value="${objectname}"/>
            </Command>
         </DataView>
         -->
      </ObjectView>

      <ObjectView type="Types">
         <DataView id="sqlserver-types-userdefineddatatypes" icon="Types" label="User Defined Data Types" viewer="grid">
            <Command idref="sqlserver.getUserTypes">
               <Input name="database" value="${catalog}"/>
            </Command>
         </DataView>
      </ObjectView>

      <ObjectView type="Procedures">
         <DataView id="generic-procedures-procedures" action="drop"/>

         <DataView id="sqlserver-procedures-procedures" icon="Procedures" label="Procedures" viewer="grid">
            <Command idref="sqlserver.getObjects">
               <Input name="database" value="${catalog}"/>
               <Input name="schema" value="${schema}"/>
               <Input name="type" value="'P'"/>
            </Command>
         </DataView>
      </ObjectView>

      <ObjectView type="Procedure">
         <DataView id="generic-procedure-columns" action="drop"/>

         <DataView classargs="PROCEDURE" id="sqlserver-procedure-procedureeditor" icon="SourceEditor" label="Procedure Editor" viewer="ProcedureViewer"
                   doclink="http://www.dbvis.com/doclink/edit-code-object"/>
         <DataView id="sqlserver-procedure-interface" icon="Interface" label="Interface" viewer="form">
            <Command idref="getProcedureColumns">
               <Input name="catalog" value="${catalog}"/>
               <Input name="schema" value="${schema}"/>
               <Input name="objectname" value="${objectname}"/>
            </Command>
         </DataView>

      </ObjectView>

      <ObjectView type="Functions">
         <DataView id="sqlserver-functions-functions" icon="Functions" label="Functions" viewer="grid">
            <Command idref="sqlserver.getObjects">
               <Input name="database" value="${catalog}"/>
               <Input name="schema" value="${schema}"/>
               <Input name="type" value="'FN', 'IF', 'TF'"/>
            </Command>
         </DataView>
      </ObjectView>

      <ObjectView type="Function">
         <DataView classargs="FUNCTION" id="sqlserver-function-functioneditor" icon="SourceEditor" label="Function Editor" viewer="ProcedureViewer"
                   doclink="http://www.dbvis.com/doclink/edit-code-object"/>
         <DataView id="sqlserver-function-interface" icon="Interface" label="Interface" viewer="form">
            <Command idref="getProcedureColumns">
               <Input name="catalog" value="${catalog}"/>
               <Input name="schema" value="${schema}"/>
               <Input name="objectname" value="${objectname}"/>
            </Command>
         </DataView>
         <!--
         <DataView type="Source" label="Source" viewer="text">
            <Command idref="sqlserver.getObjectSource">
               <Input name="database" value="${catalog}"/>
               <Input name="owner" value="${schema}"/>
               <Input name="name" value="${objectname}"/>
            </Command>
         </DataView>
-->
      </ObjectView>

      <!-- ================================================================= -->
      <!-- Linked Server Views 												 -->
      <!-- ================================================================= -->

      <ObjectView type="LinkedServers">
         <DataView id="sqlserver-linkedservers" icon="LinkedServers" label="Linked Servers" viewer="grid">
            <Command idref="sqlserver.getLinkedServers" />
         </DataView>
      </ObjectView>
	  
      <ObjectView type="LinkedServer">
         <DataView id="sqlserver-linkedserver-info" icon="Info" label="Info" viewer="node-form"/>
      </ObjectView>
      
      <ObjectView type="LinkedServerCatalogs">
         <DataView id="sqlserver-linkedserver-catalogs" icon="LinkedServerCatalogs" label="Catalogs" viewer="grid">
            <Command idref="sqlserver.getLinkedCatalogs">
               <Input name="linkedServer" value="${linkedServer}"/>
            </Command>
         </DataView>
      </ObjectView>

      <ObjectView type="LinkedServerCatalog" action="drop"/>
      
      <ObjectView type="LinkedServerSchemas">
         <DataView id="sqlserver-linkedserver-schemas" icon="LinkedServerSchemas" label="Schemas" viewer="grid">
            <Command idref="sqlserver.getLinkedSchemas">
               <Input name="linkedServer" value="${linkedServer}" />
               <Input name="linkedCatalog" value="${linkedCatalog}" />
            </Command>
         </DataView>
      </ObjectView>
      
      <ObjectView type="LinkedServerSchema" action="drop"/>
      
      <ObjectView type="LinkedServerTables">
         <DataView id="sqlserver-linkedserver-tables" icon="LinkedServerTables" label="Tables" viewer="grid">
            <Command idref="sqlserver.getLinkedTables">
               <Input name="linkedServer" value="${linkedServer}" />
               <Input name="linkedCatalog" value="${linkedCatalog}" />
               <Input name="linkedSchema" value="${linkedSchema}" />
            </Command>
         </DataView>
      </ObjectView>
         
      <ObjectView type="LinkedServerTable">
         <DataView id="sqlserver-linkedserver-table-info" icon="Info" label="Info" viewer="node-form"/>
         <DataView id="sqlserver-linkedserver-table-columns" icon="LinkedServerColumn" label="Columns" viewer="grid">
            <Command idref="sqlserver.getLinkedTableColumns">
               <Input name="linkedServer" value="${linkedServer}" />
               <Input name="linkedCatalog" value="${linkedCatalog}" />
               <Input name="linkedSchema" value="${linkedSchema}" />
               <Input name="linkedTable" value="${linkedTable}" />
            </Command>
         </DataView>
         <DataView id="sqlserver-linkedserver-table-data" icon="Data" label="Data" viewer="table-data">
            <Command idref="sqlserver.getLinkedTableData">
               <Input name="linkedServer" value="${linkedServer}" />
               <Input name="linkedCatalog" value="${linkedCatalog}" />
               <Input name="linkedSchema" value="${linkedSchema}" />
               <Input name="linkedTable" value="${linkedTable}" />
            </Command>
            <Input name="editDisabled" value="true"/>
         </DataView>
         <DataView id="sqlserver-linkedserver-table-rowcount" icon="RowCount" label="Row Count" viewer="table-rowcount">
            <Command idref="sqlserver.getLinkedTableRowCount">
               <Input name="linkedServer" value="${linkedServer}" />
               <Input name="linkedCatalog" value="${linkedCatalog}" />
               <Input name="linkedSchema" value="${linkedSchema}" />
               <Input name="linkedTable" value="${linkedTable}" />
            </Command>
         </DataView>
         <DataView id="sqlserver-linkedserver-table-primaryKey" icon="LinkedServerPrimaryKey" label="Primary Key" viewer="grid">
            <Command idref="sqlserver.getLinkedTablePrimaryKeys">
               <Input name="linkedServer" value="${linkedServer}" />
               <Input name="linkedCatalog" value="${linkedCatalog}" />
               <Input name="linkedSchema" value="${linkedSchema}" />
               <Input name="linkedTable" value="${linkedTable}" />
            </Command>
         </DataView>
<!-- sp_indexes doesn't work
		<DataView id="sqlserver-linkedserver-table-indexes" icon="Index" label="Indexes" viewer="grid">
			<Command idref="sqlserver.getLinkedTableIndexes">
				<Input name="linkedServer" value="${linkedServer}" />
				<Input name="linkedCatalog" value="${linkedCatalog}" />
				<Input name="linkedSchema" value="${linkedSchema}" />
				<Input name="linkedTable" value="${linkedTable}" />
			</Command>
		</DataView>
-->
         <DataView id="sqlserver-linkedserver-table-foreignKeys" icon="LinkedServerForeignKeys" label="Foreign Keys" viewer="grid">
            <Command idref="sqlserver.getLinkedTableForeignKeys">
               <Input name="linkedServer" value="${linkedServer}" />
               <Input name="linkedCatalog" value="${linkedCatalog}" />
               <Input name="linkedSchema" value="${linkedSchema}" />
               <Input name="linkedTable" value="${linkedTable}" />
            </Command>
         </DataView>
         <DataView id="sqlserver-linkedserver-table-grants" icon="TablePrivileges" label="Grants" viewer="grid">
            <Command idref="sqlserver.getLinkedTablePrivileges">
               <Input name="linkedCatalog" value="${linkedCatalog}"/>
               <Input name="linkedSchema" value="${linkedSchema}"/>
               <Input name="linkedTable" value="${linkedTable}"/>
            </Command>
         </DataView>
      </ObjectView>
      
      <ObjectView type="LinkedServerColumns">
         <DataView id="sqlserver-linkedserver-columns" icon="LinkedServerColumn" label="Columns" viewer="grid">
            <Command idref="sqlserver.getLinkedTableColumns">
               <Input name="linkedServer" value="${linkedServer}" />
               <Input name="linkedCatalog" value="${linkedCatalog}" />
               <Input name="linkedSchema" value="${linkedSchema}" />
               <Input name="linkedTable" value="${linkedTable}" />
            </Command>
         </DataView>
      </ObjectView>
      
      <ObjectView type="LinkedServerView">
         <DataView id="sqlserver-linkedserver-view-info" icon="Info" label="Info" viewer="node-form"/>
         <DataView id="sqlserver-linkedserver-view-columns" icon="LinkedServerColumns" label="Columns" viewer="grid">
            <Command idref="sqlserver.getLinkedTableColumns">
               <Input name="linkedServer" value="${linkedServer}" />
               <Input name="linkedCatalog" value="${linkedCatalog}" />
               <Input name="linkedSchema" value="${linkedSchema}" />
               <Input name="linkedTable" value="${linkedTable}" />
            </Command>
         </DataView>
         <DataView id="sqlserver-linkedserver-view-data" icon="Data" label="Data" viewer="table-data">
            <Command idref="sqlserver.getLinkedTableData">
               <Input name="linkedServer" value="${linkedServer}" />
               <Input name="linkedCatalog" value="${linkedCatalog}" />
               <Input name="linkedSchema" value="${linkedSchema}" />
               <Input name="linkedTable" value="${linkedTable}" />
            </Command>
            <Input name="editDisabled" value="true"/>
         </DataView>
         <DataView id="sqlserver-linkedserver-view-rowcount" icon="RowCount" label="Row Count" viewer="table-rowcount">
            <Command idref="sqlserver.getLinkedTableRowCount">
               <Input name="linkedServer" value="${linkedServer}" />
               <Input name="linkedCatalog" value="${linkedCatalog}" />
               <Input name="linkedSchema" value="${linkedSchema}" />
               <Input name="linkedTable" value="${linkedTable}" />
            </Command>
         </DataView>
      </ObjectView>

      <ObjectView type="LinkedServerColumn">
         <DataView id="sqlserver-linkedserver-table-column" icon="LinkedServerColumn" label="Column" viewer="node-form"/>
      </ObjectView>
      
      <ObjectView type="LinkedServerIndexes">
         <DataView id="sqlserver-linkedserver-indexes" icon="LinkedServerIndexes" label="Indexes" viewer="grid">
            <Command idref="sqlserver.getLinkedIndexes">
               <Input name="linkedServer" value="${linkedServer}" />
               <Input name="linkedCatalog" value="${linkedCatalog}" />
               <Input name="linkedSchema" value="${linkedSchema}" />
            </Command>
         </DataView>
      </ObjectView>
      
      <ObjectView type="LinkedServerIndex">
         <DataView id="sqlserver-linkedserver-index" icon="LinkedServerIndex" label="Index"  viewer="node-form" />
      </ObjectView>
      
      <ObjectView type="LinkedServerViews">
         <DataView id="sqlserver-linkedserver-views" icon="LinkedServerViews" label="Views" viewer="grid">
            <Command idref="sqlserver.getLinkedViews">
               <Input name="linkedServer" value="${linkedServer}" />
               <Input name="linkedCatalog" value="${linkedCatalog}" />
               <Input name="linkedSchema" value="${linkedSchema}" />
            </Command>
         </DataView>
      </ObjectView>
      
      <ObjectView type="LinkedServerSynonyms">
         <DataView id="sqlserver-linkedserver-synonyms" icon="LinkedServerSynonyms" label="Synonyms" viewer="grid">
            <Command idref="sqlserver.getLinkedSynonyms">
               <Input name="linkedServer" value="${linkedServer}" />
               <Input name="linkedCatalog" value="${linkedCatalog}" />
               <Input name="linkedSchema" value="${linkedSchema}" />
            </Command>
         </DataView>
      </ObjectView>

      <ObjectView type="LinkedServerSynonym">
         <DataView id="sqlserver-linkedserver-synonym" icon="LinkedServerSynonym" label="Column" viewer="node-form" />
      </ObjectView>
       
      <!-- ================================================================= -->
      <!-- DBA Views -->
      <!-- ================================================================= -->

      <ObjectView type="ServerInfo">
         <DataView id="sqlserver-serverinfo-serverinfo" icon="Info" label="Server Info" viewer="grid">
            <Command idref="sqlserver.serverInfo"/>
         </DataView>
         <If test="#SQL_SERVER_EDITION neq 'Azure'">
            <DataView id="sqlserver-serverinfo-serverinfo-log" icon="ErrorLog" label="Latest Error Log" viewer="grid">
               <Command idref="sqlserver.getAgentlatestErrorLog">
                  <Input name="logtype" value="1"/>
                  <!-- 1 = SQL Server -->
               </Command>
               <Message>
                  <![CDATA[ <html>Most recent log for SQL Server</html>]]>
               </Message>
            </DataView>
         </If>
      </ObjectView>

      <ObjectView type="Logins">
         <DataView id="sqlserver-logins-logins" icon="Logins" label="Logins" viewer="grid">
            <Command idref="sqlserver.getLogins"/>
         </DataView>
      </ObjectView>

      <ObjectView type="Devices">
         <DataView id="sqlserver-devices-databasedevices" icon="Devices" label="Database Devices" viewer="grid">
            <Command idref="sqlserver.getDevices"/>
         </DataView>
      </ObjectView>

      <ObjectView type="ServerRoles">
         <DataView id="sqlserver-serverroles-roles" icon="ServerRoles" label="Roles" viewer="grid">
            <Command idref="sqlserver.getServerRoles"/>
         </DataView>
      </ObjectView>

      <ObjectView type="ServerRole">
         <DataView id="sqlserver-serverrole-info" icon="Info" label="Info" viewer="node-form"/>
         <DataView id="sqlserver-serverrole-users" icon="Users" label="Users" viewer="grid">
            <Command idref="sqlserver.getServerRoleMembers">
               <Input name="database" value="${catalog}"/>
               <Input name="name" value="${objectname}"/>
            </Command>
         </DataView>
      </ObjectView>

      <ObjectView type="Processes">
         <DataView id="sqlserver-processes-processes" icon="Processes" label="Processes" viewer="grid">
            <Command idref="sqlserver.getProcesses"/>
         </DataView>
      </ObjectView>

      <ObjectView type="Locks">
         <DataView id="sqlserver-locks-locks" icon="Locks" label="Locks" viewer="grid">
            <Command idref="sqlserver.getLocks"/>
         </DataView>
      </ObjectView>

      <ObjectView type="ServerAgent">
         <DataView id="sqlserver-serveragent-serveragent" icon="ServerAgent" label="Sql Server Agent" viewer="form">
            <Command idref="sqlserver.getAgentProperties"/>
            <Message>
               <![CDATA[ <html>Properties for the Server Agent</html>]]>
            </Message>
         </DataView>

         <DataView id="sqlserver-serveragent-serveragent-log" icon="ErrorLog" label="Latest Error Log" viewer="grid">
            <Command idref="sqlserver.getAgentlatestErrorLog">
               <Input name="logtype" value="2"/>
               <!-- 2 = Agent -->
            </Command>
            <Message>
               <![CDATA[ <html>Most recent log for Server Agent</html>]]>
            </Message>
         </DataView>
      </ObjectView>

      <ObjectView type="Jobs">
         <DataView id="sqlserver-jobs-jobs" icon="Jobs" label="Jobs" viewer="grid">
            <Command idref="sqlserver.getAgentJobs">
               <Input name="jobCondition" value=""/>
               <ProcessDataSet action="dropcolumn" index="notify_level_email"/>
               <ProcessDataSet action="dropcolumn" index="IsDisabledText"/>
               <ProcessDataSet action="dropcolumn" index="notify_page_operator_id"/>
               <ProcessDataSet action="dropcolumn" index="notify_email_operator_id"/>
               <ProcessDataSet action="dropcolumn" index="notify_netsend_operator_id"/>
               <ProcessDataSet action="dropcolumn" index="notify_level_page"/>
               <ProcessDataSet action="dropcolumn" index="notify_level_netsend"/>
               <ProcessDataSet action="dropcolumn" index="notify_level_eventlog"/>
               <ProcessDataSet action="dropcolumn" index="delete_level"/>
               <ProcessDataSet action="dropcolumn" index="category_id"/>
            </Command>
            <Message>
               <![CDATA[ <html>The defined Jobs </html>]]>
            </Message>
         </DataView>
      </ObjectView>

      <ObjectView type="Job">
         <DataView id="sqlserver-jobs-job-info" icon="Info" label="info" viewer="node-form">
            <Input name="hidecolumn" value="sqlserver.getAgentJobs.notify_level_email"/>
            <Input name="hidecolumn" value="sqlserver.getAgentJobs.IsDisabledText"/>
            <Input name="hidecolumn" value="sqlserver.getAgentJobs.notify_page_operator_id"/>
            <Input name="hidecolumn" value="sqlserver.getAgentJobs.notify_email_operator_id"/>
            <Input name="hidecolumn" value="sqlserver.getAgentJobs.notify_netsend_operator_id"/>
            <Input name="hidecolumn" value="sqlserver.getAgentJobs.notify_level_page"/>
            <Input name="hidecolumn" value="sqlserver.getAgentJobs.notify_level_netsend"/>
            <Input name="hidecolumn" value="sqlserver.getAgentJobs.notify_level_eventlog"/>
            <Input name="hidecolumn" value="sqlserver.getAgentJobs.delete_level"/>
            <Input name="hidecolumn" value="sqlserver.getAgentJobs.category_id"/>
            <Message>
               <![CDATA[ <html>Properties of the Job </html>]]>
            </Message>
         </DataView>
         <DataView id="sqlserver-jobs-job-steps" icon="JobStep" label="Steps" viewer="grid">
            <Command idref="sqlserver.getAgentJobSteps">
               <Input name="jobStepCondition" value="where job_id = '${sqlserver.getAgentJobs.JobID}'"/>
               <ProcessDataSet action="dropcolumn" index="flags"/>
               <ProcessDataSet action="dropcolumn" index="on_success_action"/>
               <ProcessDataSet action="dropcolumn" index="on_fail_action"/>
               <ProcessDataSet action="dropcolumn" index="step_uid"/>
               <ProcessDataSet action="dropcolumn" index="job_id"/>
            </Command>
            <Message>
               <![CDATA[ <html>The Step information </html>]]>
            </Message>
         </DataView>

         <DataView id="sqlserver-jobs-job-alerts" icon="Alerts" label="Alerts" viewer="grid">
            <Command idref="sqlserver.getAgentAlerts">
               <Input name="condition" value="where sAl.job_id = '${sqlserver.getAgentJobs.JobID}'"/>
               <ProcessDataSet action="dropcolumn" index="jobName"/>
               <ProcessDataSet action="dropcolumn" index="job_id"/>
            </Command>
            <Message>
               <![CDATA[ <html>The Alerts </html>]]>
            </Message>
            <DataView id="sqlserver-jobs-job-allert-info" icon="Info" label="Info" viewer="node-form"/>

            <DataView id="sqlserver-jobs-job-allert-operators" icon="Operator" label="Operators" viewer="grid">
               <Command idref="sqlserver.getAgentAlertOperators">
                  <Input name="condition" value="where sNOT.alert_id = ${id}"/>
               </Command>
            </DataView>

         </DataView>

         <DataView id="sqlserver-jobs-job-stepshistory" icon="JobHistory" label="History" viewer="grid">
            <Command idref="sqlserver.getAgentJobHistory">
               <Input name="jobId" value="${sqlserver.getAgentJobs.JobID}"/>
            </Command>
            <Message>
               <![CDATA[ <html>The Job History </html>]]>
            </Message>
         </DataView>
      </ObjectView>

      <ObjectView type="JobStep">
         <DataView id="sqlserver-jobs-job-step-info" icon="Info" label="info" viewer="node-form">
            <Input name="hidecolumn" value="sqlserver.getAgentJobSteps.job_id"/>
            <Input name="hidecolumn" value="sqlserver.getAgentJobSteps.on_success_action"/>
            <Input name="hidecolumn" value="sqlserver.getAgentJobSteps.on_fail_action"/>
            <Input name="hidecolumn" value="sqlserver.getAgentJobSteps.flags"/>
            <Message>
               <![CDATA[ <html>The Step information </html>]]>
            </Message>
         </DataView>
      </ObjectView>

      <ObjectView type="SchedulerSchedules">
         <DataView id="sqlserver-scheduler-schedules" icon="SchedulerSchedule" label="Schedules" viewer="grid">
            <Command idref="sqlserver.getAgentJobSchedules">
               <Input name="condition" value=""/>
               <ProcessDataSet action="dropcolumn" index="IsDisabledText"/>
            </Command>
            <Message>
               <![CDATA[ <html>The defined Schedules </html>]]>
            </Message>
         </DataView>
      </ObjectView>

      <ObjectView type="SchedulerSchedule">
         <DataView id="sqlserver-scheduler-schedule" icon="SchedulerSchedule" label="Schedules" viewer="node-form">
            <Input name="hidecolumn" value="IsDisabledText"/>
         </DataView>
         <DataView id="sqlserver-scheduler-schedule-jobs" icon="Jobs" label="Jobs" viewer="grid">
            <Command idref="sqlserver.getAgentJobs">
               <Input name="jobCondition" value="WHERE sJOBSCH.schedule_id = ${sqlserver.getAgentJobSchedules.ScheduleID}"/>
               <ProcessDataSet action="dropcolumn" index="JobID"/>
               <ProcessDataSet action="dropcolumn" index="notify_level_email"/>
               <ProcessDataSet action="dropcolumn" index="IsDisabledText"/>
               <ProcessDataSet action="dropcolumn" index="notify_page_operator_id"/>
               <ProcessDataSet action="dropcolumn" index="notify_email_operator_id"/>
               <ProcessDataSet action="dropcolumn" index="notify_netsend_operator_id"/>
               <ProcessDataSet action="dropcolumn" index="notify_level_page"/>
               <ProcessDataSet action="dropcolumn" index="notify_level_netsend"/>
               <ProcessDataSet action="dropcolumn" index="notify_level_eventlog"/>
               <ProcessDataSet action="dropcolumn" index="delete_level"/>
               <ProcessDataSet action="dropcolumn" index="category_id"/>
            </Command>

            <Message>
               <![CDATA[ <html>The defined Jobs using the Schedule </html>]]>
            </Message>
         </DataView>
      </ObjectView>

      <ObjectView type="JobSchedules">
         <DataView id="sqlserver-jobs-schedules" icon="SchedulerSchedule" label="Schedules" viewer="grid">
            <Command idref="sqlserver.getAgentJobSchedules">
               <Input name="condition" value="INNER JOIN msdb.dbo.sysjobschedules ON msdb.dbo.sysjobschedules.schedule_id = msdb.dbo.sysschedules.schedule_id
where  msdb.dbo.sysjobschedules.job_id = '{${sqlserver.getAgentJobs.JobID}}'"/>
               <ProcessDataSet action="dropcolumn" index="IsDisabledText"/>
            </Command>
            <Message>
               <![CDATA[ <html>The defined Schedules for the job </html>]]>
            </Message>
         </DataView>
      </ObjectView>

      <ObjectView type="JobSchedule">
         <DataView id="sqlserver-jobs-schedule" icon="SchedulerSchedule" label="Schedules" viewer="node-form">
            <Input name="hidecolumn" value="sqlserver.getAgentJobSchedules.IsDisabledText"/>
            <Message>
               <![CDATA[ <html>Details about the schedule </html>]]>
            </Message>
         </DataView>
      </ObjectView>

      <ObjectView type="JobServers">
         <DataView id="sqlserver-jobs-job-target-servers" icon="JobServers" label="Servers" viewer="grid">
            <Command idref="sqlserver.getAgentJobServers">
               <Input name="jobName" value="${theJobName}"/>
            </Command>
            <Message>
               <![CDATA[ <html>The Servers where the job is running on </html>]]>
            </Message>
         </DataView>
      </ObjectView>

      <ObjectView type="JobServer">
         <DataView id="sqlserver-jobs-job-target-servers-server" icon="SchedulerSchedule" label="Server" viewer="node-form">
            <Message>
               <![CDATA[ <html>Details about the Job Server </html>]]>
            </Message>
         </DataView>
      </ObjectView>

      <ObjectView type="Alerts">
         <DataView id="sqlserver-alerts-grid" icon="Alerts" label="Alerts" viewer="grid">
            <Command idref="sqlserver.getAgentAlerts">
               <Input name="condition" value=""/>
               <ProcessDataSet action="dropcolumn" index="job_id"/>
            </Command>
            <Message>
               <![CDATA[ <html>The Alerts </html>]]>
            </Message>
         </DataView>
      </ObjectView>

      <ObjectView type="Alert">
         <DataView id="sqlserver-alerts-alert-info" icon="Alert" label="Alert" viewer="node-form">
            <Input name="hidecolumn" value="sqlserver.getAgentAlerts.job_id"/>
         </DataView>
         <DataView id="sqlserver-alerts-alert-operators" icon="Operator" label="Operators" viewer="grid">
            <Command idref="sqlserver.getAgentAlertOperators">
               <Input name="condition" value="where sNOT.alert_id = ${sqlserver.getAgentAlerts.id}"/>
            </Command>
         </DataView>
      </ObjectView>

      <ObjectView type="Operators">
         <DataView id="sqlserver-agent-operators-grid" icon="Operator" label="Operators" viewer="grid">
            <Command idref="sqlserver.getAgentOperators">
               <Input name="condition" value=""/>
            </Command>
            <Message>
               <![CDATA[ <html>The defined Operators </html>]]>
            </Message>
         </DataView>
      </ObjectView>

      <ObjectView type="Operator">
         <DataView id="sqlserver-agent-operators-operator-info" icon="Info" label="Info" viewer="node-form"/>
         <DataView id="sqlserver-agent-operators-operator-alerts" icon="Alert" label="Alerts" viewer="grid">
            <Command idref="sqlserver.getAgentOperatorAlerts">
               <Input name="operatorId" value="${sqlserver.getAgentOperators.id}"/>
               <ProcessDataSet action="dropcolumn" index="name"/>
            </Command>
         </DataView>
         <!-- HERE -->
         <DataView id="sqlserver-agent-operators-operator-jobs" icon="Job" label="Jobs" viewer="grid">
            <Command idref="sqlserver.getAgentJobs">
               <Input name="jobCondition" value="WHERE sJOB.notify_email_operator_id = ${sqlserver.getAgentOperators.id} OR
                                                 sJOB.notify_netsend_operator_id = ${sqlserver.getAgentOperators.id} OR
                                                 sJOB.notify_page_operator_id = ${sqlserver.getAgentOperators.id}"/>
               <ProcessDataSet action="dropcolumn" index="jobID"/>
               <ProcessDataSet action="dropcolumn" index="notify_level_email"/>
               <ProcessDataSet action="dropcolumn" index="IsDisabledText"/>
               <ProcessDataSet action="dropcolumn" index="notify_page_operator_id"/>
               <ProcessDataSet action="dropcolumn" index="notify_email_operator_id"/>
               <ProcessDataSet action="dropcolumn" index="notify_netsend_operator_id"/>
               <ProcessDataSet action="dropcolumn" index="notify_level_page"/>
               <ProcessDataSet action="dropcolumn" index="notify_level_netsend"/>
               <ProcessDataSet action="dropcolumn" index="notify_level_eventlog"/>
               <ProcessDataSet action="dropcolumn" index="delete_level"/>
            </Command>
         </DataView>

      </ObjectView>

   </ObjectsViewDef>

</DatabaseProfile>
