text: -- Script generated by Aqua Data Studio Schema Synchronization for MS SQL Server 2016 on Fri Oct 22 23:45:44 PDT 2021
  -- Execute this script on:
  -- 		PIMS_S13_00/<All Schemas> - This database/schema will be modified
  -- to synchronize it with MS SQL Server 2016:
  -- 		PIMS_S11_01/<All Schemas>
  
  -- We recommend backing up the database prior to executing the script.
  
  SET XACT_ABORT ON
  GO
  SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
  GO
  BEGIN TRANSACTION
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop foreign key constraint PIM_LSTERM_PIM_LPFCST_FK
  PRINT N'Drop foreign key constraint PIM_LSTERM_PIM_LPFCST_FK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_PAYMENT_FORECAST]
  	DROP CONSTRAINT [PIM_LSTERM_PIM_LPFCST_FK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop foreign key constraint PIM_LPYPER_PIM_LPFCST_FK
  PRINT N'Drop foreign key constraint PIM_LPYPER_PIM_LPFCST_FK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_PAYMENT_FORECAST]
  	DROP CONSTRAINT [PIM_LPYPER_PIM_LPFCST_FK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop foreign key constraint PIM_LPSTST_PIM_LPFCST_FK
  PRINT N'Drop foreign key constraint PIM_LPSTST_PIM_LPFCST_FK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_PAYMENT_FORECAST]
  	DROP CONSTRAINT [PIM_LPSTST_PIM_LPFCST_FK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop foreign key constraint PIM_LPYPER_PIM_LSPYMT_FK
  PRINT N'Drop foreign key constraint PIM_LPYPER_PIM_LSPYMT_FK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_PAYMENT]
  	DROP CONSTRAINT [PIM_LPYPER_PIM_LSPYMT_FK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop foreign key constraint PIM_LSPMMT_PIM_LSPYMT_FK
  PRINT N'Drop foreign key constraint PIM_LSPMMT_PIM_LSPYMT_FK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_PAYMENT]
  	DROP CONSTRAINT [PIM_LSPMMT_PIM_LSPYMT_FK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop foreign key constraint PIM_LSTERM_PIM_LSPYMT_FK
  PRINT N'Drop foreign key constraint PIM_LSTERM_PIM_LSPYMT_FK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_PAYMENT]
  	DROP CONSTRAINT [PIM_LSTERM_PIM_LSPYMT_FK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop foreign key constraint PIM_LTRMST_PIM_LSTERM_FK
  PRINT N'Drop foreign key constraint PIM_LTRMST_PIM_LSTERM_FK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_TERM]
  	DROP CONSTRAINT [PIM_LTRMST_PIM_LSTERM_FK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop foreign key constraint PIM_LEASE_PIM_LSTERM_FK
  PRINT N'Drop foreign key constraint PIM_LEASE_PIM_LSTERM_FK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_TERM]
  	DROP CONSTRAINT [PIM_LEASE_PIM_LSTERM_FK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop foreign key constraint PIM_LRESPT_PIM_LEASE_FK
  PRINT N'Drop foreign key constraint PIM_LRESPT_PIM_LEASE_FK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE]
  	DROP CONSTRAINT [PIM_LRESPT_PIM_LEASE_FK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop foreign key constraint PIM_LINITT_PIM_LEASE_FK
  PRINT N'Drop foreign key constraint PIM_LINITT_PIM_LEASE_FK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE]
  	DROP CONSTRAINT [PIM_LINITT_PIM_LEASE_FK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop index pmbc.PRCPLY_PID_NUMBER_IDX
  PRINT N'Drop index pmbc.PRCPLY_PID_NUMBER_IDX'
  GO
  DROP INDEX [pmbc].[PMBC_PARCEL_POLYGON_FABRIC].[PRCPLY_PID_NUMBER_IDX]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_CLMTYP_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_CLMTYP_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_CLMTYP_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_USRORG_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_USRORG_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_USRORG_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ACTVTY_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_ACTVTY_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ACTVTY_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_TENANT_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_TENANT_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_TENANT_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LELIST_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_LELIST_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LELIST_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_REGION_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_REGION_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_REGION_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_CNTRY_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_CNTRY_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_CNTRY_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ACRQST_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_ACRQST_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ACRQST_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LSSRTY_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_LSSRTY_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LSSRTY_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_TENANT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_TENANT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_TENANT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PROJNT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PROJNT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PROJNT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ORG_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_ORG_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ORG_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LTRMST_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_LTRMST_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LTRMST_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LTRMST_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_LTRMST_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LTRMST_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_CLMTYP_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_CLMTYP_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_CLMTYP_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ACTVTY_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_ACTVTY_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ACTVTY_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRJTYP_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PRJTYP_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRJTYP_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ORGTYP_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_ORGTYP_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ORGTYP_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_USER_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_USER_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_USER_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPRSF_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PRPRSF_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPRSF_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ADDRSS_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_ADDRSS_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ADDRSS_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_TSKTMP_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_TSKTMP_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_TSKTMP_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_CLMTYP_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_CLMTYP_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_CLMTYP_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_SECDPT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_SECDPT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_SECDPT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_USRORG_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_USRORG_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_USRORG_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_INSPYT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_INSPYT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_INSPYT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPTAX_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_PRPTAX_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPTAX_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_CNTRY_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_CNTRY_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_CNTRY_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ARQSTT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_ARQSTT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ARQSTT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PROPLS_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_PROPLS_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PROPLS_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRJRSK_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PRJRSK_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRJRSK_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LELIST_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_LELIST_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LELIST_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPRSF_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_PRPRSF_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPRSF_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LSPRTY_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_LSPRTY_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LSPRTY_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LSSRTY_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_LSSRTY_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LSSRTY_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PERSON_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_PERSON_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PERSON_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPTNR_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PRPTNR_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPTNR_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPRSF_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PRPRSF_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPRSF_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPRTY_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_PRPRTY_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPRTY_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_TSKTMP_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_TSKTMP_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_TSKTMP_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_SECDPT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_SECDPT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_SECDPT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ORG_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_ORG_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ORG_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LSCATT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_LSCATT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LSCATT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_TSKTMP_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_TSKTMP_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_TSKTMP_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRSVFT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PRSVFT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRSVFT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_SPDCLT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_SPDCLT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_SPDCLT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_SECDEP_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_SECDEP_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_SECDEP_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_SPDCLT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_SPDCLT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_SPDCLT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LSPMTF_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_LSPMTF_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LSPMTF_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LSPMMT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_LSPMMT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LSPMMT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LSPMMT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_LSPMMT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LSPMMT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_INSRNC_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_INSRNC_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_INSRNC_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ROLE_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_ROLE_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ROLE_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPACT_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_PRPACT_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPACT_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRJSTY_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PRJSTY_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRJSTY_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPSVC_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_PRPSVC_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPSVC_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PROPLS_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PROPLS_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PROPLS_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_WFLMDL_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_WFLMDL_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_WFLMDL_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PIMPRV_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_PIMPRV_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PIMPRV_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRJPRP_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PRJPRP_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRJPRP_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_CNTMTH_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_CNTMTH_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_CNTMTH_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ACTVTY_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_ACTVTY_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ACTVTY_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_TSKTAM_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_TSKTAM_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_TSKTAM_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRSVFT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PRSVFT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRSVFT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPTYP_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PRPTYP_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPTYP_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PROVNC_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PROVNC_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PROVNC_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_WFLMDL_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_WFLMDL_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_WFLMDL_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ACRQOR_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_ACRQOR_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ACRQOR_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_INSRNC_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_INSRNC_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_INSRNC_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LSCATT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_LSCATT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LSCATT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LRESPT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_LRESPT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LRESPT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LRESPT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_LRESPT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LRESPT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LPYPER_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_LPYPER_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LPYPER_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LPYPER_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_LPYPER_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LPYPER_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LPYPER_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_LPYPER_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LPYPER_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LPSTST_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_LPSTST_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LPSTST_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LPSTST_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_LPSTST_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LPSTST_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ORG_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_ORG_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ORG_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_TASK_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_TASK_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_TASK_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PROJTR_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PROJTR_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PROJTR_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPSTS_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PRPSTS_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPSTS_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_SCHLDT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_SCHLDT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_SCHLDT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PERORG_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_PERORG_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PERORG_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ACTMDL_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_ACTMDL_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ACTMDL_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_TENANT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_TENANT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_TENANT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_CNTMTH_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_CNTMTH_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_CNTMTH_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ACRQOR_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_ACRQOR_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ACRQOR_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PROPLS_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PROPLS_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PROPLS_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_WFLMDL_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_WFLMDL_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_WFLMDL_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PROVNC_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PROVNC_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PROVNC_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRJTYP_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PRJTYP_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRJTYP_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_SECDEP_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_SECDEP_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_SECDEP_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ORGTYP_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_ORGTYP_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ORGTYP_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPCLT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PRPCLT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPCLT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRJPRP_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PRJPRP_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRJPRP_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ORGIDT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_ORGIDT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ORGIDT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_WFLMDT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_WFLMDT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_WFLMDT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPTYP_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PRPTYP_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPTYP_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PIMPRV_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PIMPRV_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PIMPRV_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_TSKTMT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_TSKTMT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_TSKTMT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_SCHLDT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_SCHLDT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_SCHLDT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ROLCLM_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_ROLCLM_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ROLCLM_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LPRPTY_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_LPRPTY_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LPRPTY_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ACRQST_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_ACRQST_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ACRQST_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRJPRP_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_PRJPRP_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRJPRP_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRWKMD_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PRWKMD_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRWKMD_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_TASK_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_TASK_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_TASK_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PERSON_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PERSON_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PERSON_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_SDRTRN_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_SDRTRN_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_SDRTRN_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ARUNIT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_ARUNIT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ARUNIT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_WFLMDT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_WFLMDT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_WFLMDT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ROLCLM_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_ROLCLM_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ROLCLM_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPORG_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PRPORG_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPORG_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PIMPRV_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PIMPRV_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PIMPRV_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_CNTMTH_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_CNTMTH_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_CNTMTH_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPSTS_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PRPSTS_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPSTS_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ACTMDL_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_ACTMDL_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ACTMDL_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LSPRGT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_LSPRGT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LSPRGT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PROJTR_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PROJTR_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PROJTR_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LEASE_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_LEASE_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LEASE_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop index dbo.LEASE_LEASE_RESPONSIBILITY_TYPE_CODE_IDX
  PRINT N'Drop index dbo.LEASE_LEASE_RESPONSIBILITY_TYPE_CODE_IDX'
  GO
  DROP INDEX [dbo].[PIMS_LEASE].[LEASE_LEASE_RESPONSIBILITY_TYPE_CODE_IDX]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop index dbo.LEASE_LEASE_INITIATOR_TYPE_CODE_IDX
  PRINT N'Drop index dbo.LEASE_LEASE_INITIATOR_TYPE_CODE_IDX'
  GO
  DROP INDEX [dbo].[PIMS_LEASE].[LEASE_LEASE_INITIATOR_TYPE_CODE_IDX]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ACRQST_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_ACRQST_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ACRQST_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPCLT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PRPCLT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPCLT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ACRQOR_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_ACRQOR_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ACRQOR_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ORGIDT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_ORGIDT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ORGIDT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_TSKTMT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_TSKTMT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_TSKTMT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPORG_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_PRPORG_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPORG_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_SECDEP_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_SECDEP_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_SECDEP_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LPRPTY_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_LPRPTY_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LPRPTY_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPRTY_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PRPRTY_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPRTY_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PIDSRT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PIDSRT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PIDSRT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRWKMD_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PRWKMD_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRWKMD_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PERSON_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PERSON_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PERSON_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPRTY_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PRPRTY_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPRTY_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ACTMDL_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_ACTMDL_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ACTMDL_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRJSTY_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PRJSTY_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRJSTY_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LSPMTF_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_LSPMTF_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LSPMTF_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPORG_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PRPORG_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPORG_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LSPRGT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_LSPRGT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LSPRGT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_USRORG_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_USRORG_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_USRORG_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_TSKTAM_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_TSKTAM_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_TSKTAM_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PERORG_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PERORG_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PERORG_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_INSPAY_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_INSPAY_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_INSPAY_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPACT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PRPACT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPACT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PIDSRT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PIDSRT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PIDSRT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPSVC_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PRPSVC_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPSVC_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ROLE_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_ROLE_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ROLE_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ARQSTT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_ARQSTT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ARQSTT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_INSPYT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_INSPYT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_INSPYT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPEVL_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PRPEVL_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPEVL_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PIMPRT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PIMPRT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PIMPRT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_SDRTRN_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_SDRTRN_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_SDRTRN_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LSPRTY_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_LSPRTY_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LSPRTY_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRJRSK_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PRJRSK_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRJRSK_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_USER_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_USER_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_USER_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PROJCT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PROJCT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PROJCT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_INSRNC_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_INSRNC_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_INSRNC_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPACT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PRPACT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPACT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LEASE_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_LEASE_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LEASE_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ADDRSS_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_ADDRSS_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ADDRSS_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPTNR_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PRPTNR_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPTNR_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ADUSGT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_ADUSGT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ADUSGT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_USERRL_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_USERRL_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_USERRL_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_CNTMTT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_CNTMTT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_CNTMTT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_USERRL_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_USERRL_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_USERRL_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PERORG_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PERORG_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PERORG_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ADDRSS_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_ADDRSS_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ADDRSS_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_TASK_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_TASK_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_TASK_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_TSKTAM_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_TSKTAM_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_TSKTAM_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PROJNT_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_PROJNT_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PROJNT_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPTAX_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PRPTAX_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPTAX_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_DSTRCT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_DSTRCT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_DSTRCT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ROLE_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_ROLE_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ROLE_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_REGION_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_REGION_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_REGION_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_INSPAY_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_INSPAY_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_INSPAY_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PTRMTT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PTRMTT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PTRMTT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_SDRTRN_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_SDRTRN_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_SDRTRN_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPSVC_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PRPSVC_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPSVC_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_USER_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_USER_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_USER_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ROLCLM_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_ROLCLM_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ROLCLM_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPEVL_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PRPEVL_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPEVL_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ARUNIT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_ARUNIT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ARUNIT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PIMPRT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PIMPRT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PIMPRT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PTRMTT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PTRMTT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PTRMTT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPEVL_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_PRPEVL_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPEVL_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRPTAX_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PRPTAX_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRPTAX_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PROJCT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_PROJCT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PROJCT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_DSTRCT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_DSTRCT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_DSTRCT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PROJCT_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_PROJCT_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PROJCT_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_ADUSGT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_ADUSGT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_ADUSGT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PRWKMD_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_PRWKMD_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PRWKMD_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_CNTMTT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_CNTMTT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_CNTMTT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_USERRL_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_USERRL_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_USERRL_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_PROJNT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_PROJNT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_PROJNT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LEASE_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_LEASE_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LEASE_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LPFCST_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_LPFCST_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LPFCST_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LPFCST_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_LPFCST_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LPFCST_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LPFCST_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_LPFCST_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LPFCST_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LINITT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_LINITT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LINITT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LINITT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_LINITT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LINITT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop index dbo.LPFCST_LEASE_TERM_ID_IDX
  PRINT N'Drop index dbo.LPFCST_LEASE_TERM_ID_IDX'
  GO
  DROP INDEX [dbo].[PIMS_LEASE_PAYMENT_FORECAST].[LPFCST_LEASE_TERM_ID_IDX]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop index dbo.LPFCST_LEASE_PAYMENT_STATUS_TYPE_CODE_IDX
  PRINT N'Drop index dbo.LPFCST_LEASE_PAYMENT_STATUS_TYPE_CODE_IDX'
  GO
  DROP INDEX [dbo].[PIMS_LEASE_PAYMENT_FORECAST].[LPFCST_LEASE_PAYMENT_STATUS_TYPE_CODE_IDX]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop index dbo.LPFCST_LEASE_PAYMENT_PERIOD_ID_IDX
  PRINT N'Drop index dbo.LPFCST_LEASE_PAYMENT_PERIOD_ID_IDX'
  GO
  DROP INDEX [dbo].[PIMS_LEASE_PAYMENT_FORECAST].[LPFCST_LEASE_PAYMENT_PERIOD_ID_IDX]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LSPYMT_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_LSPYMT_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LSPYMT_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LSPYMT_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_LSPYMT_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LSPYMT_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LSPYMT_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_LSPYMT_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LSPYMT_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop index dbo.LSPYMT_LEASE_TERM_ID_IDX
  PRINT N'Drop index dbo.LSPYMT_LEASE_TERM_ID_IDX'
  GO
  DROP INDEX [dbo].[PIMS_LEASE_PAYMENT].[LSPYMT_LEASE_TERM_ID_IDX]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop index dbo.LSPYMT_LEASE_PAYMENT_PERIOD_ID_IDX
  PRINT N'Drop index dbo.LSPYMT_LEASE_PAYMENT_PERIOD_ID_IDX'
  GO
  DROP INDEX [dbo].[PIMS_LEASE_PAYMENT].[LSPYMT_LEASE_PAYMENT_PERIOD_ID_IDX]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop index dbo.LSPYMT_LEASE_PAYMENT_METHOD_TYPE_CODE_IDX
  PRINT N'Drop index dbo.LSPYMT_LEASE_PAYMENT_METHOD_TYPE_CODE_IDX'
  GO
  DROP INDEX [dbo].[PIMS_LEASE_PAYMENT].[LSPYMT_LEASE_PAYMENT_METHOD_TYPE_CODE_IDX]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LSTERM_I_S_U_TR
  PRINT N'Drop trigger dbo.PIMS_LSTERM_I_S_U_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LSTERM_I_S_U_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LSTERM_I_S_I_TR
  PRINT N'Drop trigger dbo.PIMS_LSTERM_I_S_I_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LSTERM_I_S_I_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop trigger dbo.PIMS_LSTERM_A_S_IUD_TR
  PRINT N'Drop trigger dbo.PIMS_LSTERM_A_S_IUD_TR'
  GO
  DROP TRIGGER [dbo].[PIMS_LSTERM_A_S_IUD_TR]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop index dbo.LSTERM_LEASE_TERM_STATUS_TYPE_CODE_IDX
  PRINT N'Drop index dbo.LSTERM_LEASE_TERM_STATUS_TYPE_CODE_IDX'
  GO
  DROP INDEX [dbo].[PIMS_LEASE_TERM].[LSTERM_LEASE_TERM_STATUS_TYPE_CODE_IDX]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop index dbo.LSTERM_LEASE_ID_IDX
  PRINT N'Drop index dbo.LSTERM_LEASE_ID_IDX'
  GO
  DROP INDEX [dbo].[PIMS_LEASE_TERM].[LSTERM_LEASE_ID_IDX]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop primary key constraint PRCPLY_PK
  PRINT N'Drop primary key constraint PRCPLY_PK'
  GO
  ALTER TABLE [pmbc].[PMBC_PARCEL_POLYGON_FABRIC]
  	DROP CONSTRAINT [PRCPLY_PK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop view dbo.PIMS_PROPERTY_LOCATION_VW
  PRINT N'Drop view dbo.PIMS_PROPERTY_LOCATION_VW'
  GO
  DROP VIEW [dbo].[PIMS_PROPERTY_LOCATION_VW]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop view dbo.PIMS_PROPERTY_BOUNDARY_VW
  PRINT N'Drop view dbo.PIMS_PROPERTY_BOUNDARY_VW'
  GO
  DROP VIEW [dbo].[PIMS_PROPERTY_BOUNDARY_VW]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop unique constraint PIMS_LPYPER_H_UK
  PRINT N'Drop unique constraint PIMS_LPYPER_H_UK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_PAYMENT_PERIOD_HIST]
  	DROP CONSTRAINT [PIMS_LPYPER_H_UK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop primary key constraint PIMS_LPYPER_H_PK
  PRINT N'Drop primary key constraint PIMS_LPYPER_H_PK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_PAYMENT_PERIOD_HIST]
  	DROP CONSTRAINT [PIMS_LPYPER_H_PK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop procedure dbo.pims_error_handling
  PRINT N'Drop procedure dbo.pims_error_handling'
  GO
  DROP PROCEDURE [dbo].[pims_error_handling]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop unique constraint PIMS_LPFCST_H_UK
  PRINT N'Drop unique constraint PIMS_LPFCST_H_UK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_PAYMENT_FORECAST_HIST]
  	DROP CONSTRAINT [PIMS_LPFCST_H_UK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop primary key constraint PIMS_LPFCST_H_PK
  PRINT N'Drop primary key constraint PIMS_LPFCST_H_PK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_PAYMENT_FORECAST_HIST]
  	DROP CONSTRAINT [PIMS_LPFCST_H_PK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop primary key constraint LPFCST_PK
  PRINT N'Drop primary key constraint LPFCST_PK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_PAYMENT_FORECAST]
  	DROP CONSTRAINT [LPFCST_PK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop table dbo.PIMS_LEASE_PAYMENT_FORECAST
  PRINT N'Drop table dbo.PIMS_LEASE_PAYMENT_FORECAST'
  GO
  DROP TABLE [dbo].[PIMS_LEASE_PAYMENT_FORECAST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop primary key constraint LPSTST_PK
  PRINT N'Drop primary key constraint LPSTST_PK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_PAYMENT_STATUS_TYPE]
  	DROP CONSTRAINT [LPSTST_PK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop unique constraint PIMS_LSPYMT_H_UK
  PRINT N'Drop unique constraint PIMS_LSPYMT_H_UK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_PAYMENT_HIST]
  	DROP CONSTRAINT [PIMS_LSPYMT_H_UK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop primary key constraint PIMS_LSPYMT_H_PK
  PRINT N'Drop primary key constraint PIMS_LSPYMT_H_PK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_PAYMENT_HIST]
  	DROP CONSTRAINT [PIMS_LSPYMT_H_PK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop primary key constraint LSPYMT_PK
  PRINT N'Drop primary key constraint LSPYMT_PK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_PAYMENT]
  	DROP CONSTRAINT [LSPYMT_PK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop table dbo.PIMS_LEASE_PAYMENT
  PRINT N'Drop table dbo.PIMS_LEASE_PAYMENT'
  GO
  DROP TABLE [dbo].[PIMS_LEASE_PAYMENT]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop primary key constraint LPYPER_PK
  PRINT N'Drop primary key constraint LPYPER_PK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_PAYMENT_PERIOD]
  	DROP CONSTRAINT [LPYPER_PK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop table dbo.PIMS_LEASE_PAYMENT_PERIOD
  PRINT N'Drop table dbo.PIMS_LEASE_PAYMENT_PERIOD'
  GO
  DROP TABLE [dbo].[PIMS_LEASE_PAYMENT_PERIOD]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop primary key constraint LSPMMT_PK
  PRINT N'Drop primary key constraint LSPMMT_PK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_PAYMENT_METHOD_TYPE]
  	DROP CONSTRAINT [LSPMMT_PK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop unique constraint PIMS_LSTERM_H_UK
  PRINT N'Drop unique constraint PIMS_LSTERM_H_UK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_TERM_HIST]
  	DROP CONSTRAINT [PIMS_LSTERM_H_UK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop primary key constraint PIMS_LSTERM_H_PK
  PRINT N'Drop primary key constraint PIMS_LSTERM_H_PK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_TERM_HIST]
  	DROP CONSTRAINT [PIMS_LSTERM_H_PK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop primary key constraint LSTERM_PK
  PRINT N'Drop primary key constraint LSTERM_PK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_TERM]
  	DROP CONSTRAINT [LSTERM_PK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop table dbo.PIMS_LEASE_TERM
  PRINT N'Drop table dbo.PIMS_LEASE_TERM'
  GO
  DROP TABLE [dbo].[PIMS_LEASE_TERM]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop primary key constraint LTRMST_PK
  PRINT N'Drop primary key constraint LTRMST_PK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_TERM_STATUS_TYPE]
  	DROP CONSTRAINT [LTRMST_PK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop primary key constraint LRESPT_PK
  PRINT N'Drop primary key constraint LRESPT_PK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_RESPONSIBILITY_TYPE]
  	DROP CONSTRAINT [LRESPT_PK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop primary key constraint LINITT_PK
  PRINT N'Drop primary key constraint LINITT_PK'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_INITIATOR_TYPE]
  	DROP CONSTRAINT [LINITT_PK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop primary key constraint STAVBL_PK
  PRINT N'Drop primary key constraint STAVBL_PK'
  GO
  ALTER TABLE [dbo].[PIMS_STATIC_VARIABLE]
  	DROP CONSTRAINT [STAVBL_PK]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop table dbo.PIMS_STATIC_VARIABLE
  PRINT N'Drop table dbo.PIMS_STATIC_VARIABLE'
  GO
  DROP TABLE [dbo].[PIMS_STATIC_VARIABLE]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop table etl.ETL_ERROR_LOG
  PRINT N'Drop table etl.ETL_ERROR_LOG'
  GO
  DROP TABLE [etl].[ETL_ERROR_LOG]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop table etl.ETL_PROPERTY_ERROR_LOG
  PRINT N'Drop table etl.ETL_PROPERTY_ERROR_LOG'
  GO
  DROP TABLE [etl].[ETL_PROPERTY_ERROR_LOG]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop sequence dbo.PIMS_LEASE_TERM_ID_SEQ
  PRINT N'Drop sequence dbo.PIMS_LEASE_TERM_ID_SEQ'
  GO
  DROP SEQUENCE [dbo].[PIMS_LEASE_TERM_ID_SEQ]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table etl.ETL_CONTACT_METHOD_LOG
  PRINT N'Alter table etl.ETL_CONTACT_METHOD_LOG'
  GO
  ALTER TABLE [etl].[ETL_CONTACT_METHOD_LOG] DROP CONSTRAINT [CNTMTH_DB_LAST_UPDATE_TIMESTAMP_DEF]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [etl].[ETL_CONTACT_METHOD_LOG] DROP CONSTRAINT [CNTMTH_DB_LAST_UPDATE_USERID_DEF]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create sequence dbo.PIMS_EXPECTED_AMOUNT_H_ID_SEQ
  PRINT N'Create sequence dbo.PIMS_EXPECTED_AMOUNT_H_ID_SEQ'
  GO
  CREATE SEQUENCE [dbo].[PIMS_EXPECTED_AMOUNT_H_ID_SEQ]
  	AS bigint
  	START WITH 1
  	INCREMENT BY 1
  	MINVALUE 1
  	MAXVALUE 2147483647
  	NO CYCLE
  	CACHE 50
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create sequence dbo.PIMS_EXPECTED_AMOUNT_ID_SEQ
  PRINT N'Create sequence dbo.PIMS_EXPECTED_AMOUNT_ID_SEQ'
  GO
  CREATE SEQUENCE [dbo].[PIMS_EXPECTED_AMOUNT_ID_SEQ]
  	AS bigint
  	START WITH 1
  	INCREMENT BY 1
  	MINVALUE 1
  	MAXVALUE 2147483647
  	NO CYCLE
  	CACHE 50
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create sequence dbo.PIMS_LEASE_ACTIVITY_H_ID_SEQ
  PRINT N'Create sequence dbo.PIMS_LEASE_ACTIVITY_H_ID_SEQ'
  GO
  CREATE SEQUENCE [dbo].[PIMS_LEASE_ACTIVITY_H_ID_SEQ]
  	AS bigint
  	START WITH 1
  	INCREMENT BY 1
  	MINVALUE 1
  	MAXVALUE 2147483647
  	NO CYCLE
  	CACHE 50
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create sequence dbo.PIMS_LEASE_ACTIVITY_PERIOD_H_ID_SEQ
  PRINT N'Create sequence dbo.PIMS_LEASE_ACTIVITY_PERIOD_H_ID_SEQ'
  GO
  CREATE SEQUENCE [dbo].[PIMS_LEASE_ACTIVITY_PERIOD_H_ID_SEQ]
  	AS bigint
  	START WITH 1
  	INCREMENT BY 1
  	MINVALUE 1
  	MAXVALUE 2147483647
  	NO CYCLE
  	CACHE 50
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create table dbo.PIMS_PROPERTY_IMPROVEMENT_UOM_TYPE
  PRINT N'Create table dbo.PIMS_PROPERTY_IMPROVEMENT_UOM_TYPE'
  GO
  CREATE TABLE [dbo].[PIMS_PROPERTY_IMPROVEMENT_UOM_TYPE]  ( 
  	[CONCURRENCY_CONTROL_NUMBER]        	bigint NOT NULL CONSTRAINT [PIMPRU_CONCURRENCY_CONTROL_NUMBER_DEF]  DEFAULT ((1)),
  	[DB_CREATE_TIMESTAMP]               	datetime NOT NULL CONSTRAINT [PIMPRU_DB_CREATE_TIMESTAMP_DEF]  DEFAULT (getutcdate()),
  	[DB_CREATE_USERID]                  	nvarchar(30) NOT NULL CONSTRAINT [PIMPRU_DB_CREATE_USERID_DEF]  DEFAULT (user_name()),
  	[DB_LAST_UPDATE_TIMESTAMP]          	datetime NOT NULL CONSTRAINT [PIMPRU_DB_LAST_UPDATE_TIMESTAMP_DEF]  DEFAULT (getutcdate()),
  	[DB_LAST_UPDATE_USERID]             	nvarchar(30) NOT NULL CONSTRAINT [PIMPRU_DB_LAST_UPDATE_USERID_DEF]  DEFAULT (user_name()),
  	[DESCRIPTION]                       	nvarchar(200) NOT NULL,
  	[DISPLAY_ORDER]                     	int NULL,
  	[IS_DISABLED]                       	bit NOT NULL CONSTRAINT [PIMPRU_IS_DISABLED_DEF]  DEFAULT (CONVERT([bit],(0))),
  	[PROPERTY_IMPROVEMENT_UOM_TYPE_CODE]	nvarchar(20) NOT NULL,
  	CONSTRAINT [PIMPRU_PK] PRIMARY KEY CLUSTERED([PROPERTY_IMPROVEMENT_UOM_TYPE_CODE])
   ON [PRIMARY])
  GO
  EXEC sp_addextendedproperty 
  	@name = N'MS_Description', @value = N'Code description of the unit of measure of the property improvement' , 
  	@level0type = N'Schema', @level0name = N'dbo', 
  	@level1type = N'Table', @level1name = N'PIMS_PROPERTY_IMPROVEMENT_UOM_TYPE', 
  	@level2type = N'Column', @level2name = N'DESCRIPTION'
  GO
  EXEC sp_addextendedproperty 
  	@name = N'MS_Description', @value = N'Indicates if the code is disabled' , 
  	@level0type = N'Schema', @level0name = N'dbo', 
  	@level1type = N'Table', @level1name = N'PIMS_PROPERTY_IMPROVEMENT_UOM_TYPE', 
  	@level2type = N'Column', @level2name = N'IS_DISABLED'
  GO
  EXEC sp_addextendedproperty 
  	@name = N'MS_Description', @value = N'Code value of the unit of measure of the property improvement' , 
  	@level0type = N'Schema', @level0name = N'dbo', 
  	@level1type = N'Table', @level1name = N'PIMS_PROPERTY_IMPROVEMENT_UOM_TYPE', 
  	@level2type = N'Column', @level2name = N'PROPERTY_IMPROVEMENT_UOM_TYPE_CODE'
  GO
  EXEC sp_addextendedproperty 
  	@name = N'MS_Description', @value = N'Description of the unit of measure of the property improvement' , 
  	@level0type = N'Schema', @level0name = N'dbo', 
  	@level1type = N'Table', @level1name = N'PIMS_PROPERTY_IMPROVEMENT_UOM_TYPE'
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_ADDRESS
  PRINT N'Alter table dbo.PIMS_ADDRESS'
  GO
  ALTER TABLE [dbo].[PIMS_ADDRESS]
  	DROP COLUMN [COMMENT]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_PERSON
  PRINT N'Alter table dbo.PIMS_PERSON'
  GO
  ALTER TABLE [dbo].[PIMS_PERSON]
  	DROP COLUMN [PREFERRED_NAME]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_LEASE
  PRINT N'Alter table dbo.PIMS_LEASE'
  GO
  UPDATE [dbo].[PIMS_LEASE] SET [RENEWAL_COUNT] = ((0)) WHERE [RENEWAL_COUNT] IS NULL
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_LEASE] ALTER COLUMN [RENEWAL_COUNT] smallint NOT NULL
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_LEASE] ADD CONSTRAINT [LEASE_RENEWAL_COUNT_DEF] DEFAULT ((0)) FOR [RENEWAL_COUNT]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  EXEC sp_updateextendedproperty 
  	@name = N'MS_Description', @value = N'Zero-based count of lease renewals' , 
  	@level0type = N'Schema', @level0name = N'dbo', 
  	@level1type = N'Table', @level1name = N'PIMS_LEASE', 
  	@level2type = N'Column', @level2name = N'RENEWAL_COUNT'
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  EXEC sp_updateextendedproperty 
  	@name = N'MS_Description', @value = N'Number of months in a renewal term' , 
  	@level0type = N'Schema', @level0name = N'dbo', 
  	@level1type = N'Table', @level1name = N'PIMS_LEASE', 
  	@level2type = N'Column', @level2name = N'RENEWAL_TERM_MONTHS'
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_LEASE]
  	DROP CONSTRAINT [LEASE_IS_COMM_BLDG_DEF]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_LEASE]
  	DROP CONSTRAINT [LEASE_IS_OTHER_IMPROVEMENT_DEF]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_LEASE]
  	DROP CONSTRAINT [LEASE_IS_SUBJECT_TO_RTA_DEF]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_LEASE]
  	ADD [TERM_EXPIRY_DATE] datetime NULL, 
  	[TERM_RENEWAL_DATE] datetime NULL, 
  	[TERM_START_DATE] datetime NULL
  GO
  EXEC sp_addextendedproperty 
  	@name = N'MS_Description', @value = N'Expiry date of the current term of the lease/licence' , 
  	@level0type = N'Schema', @level0name = N'dbo', 
  	@level1type = N'Table', @level1name = N'PIMS_LEASE', 
  	@level2type = N'Column', @level2name = N'TERM_EXPIRY_DATE'
  GO
  EXEC sp_addextendedproperty 
  	@name = N'MS_Description', @value = N'Renewal date of the current term of the lease/licence' , 
  	@level0type = N'Schema', @level0name = N'dbo', 
  	@level1type = N'Table', @level1name = N'PIMS_LEASE', 
  	@level2type = N'Column', @level2name = N'TERM_RENEWAL_DATE'
  GO
  EXEC sp_addextendedproperty 
  	@name = N'MS_Description', @value = N'Start date of the current term of the lease/licence' , 
  	@level0type = N'Schema', @level0name = N'dbo', 
  	@level1type = N'Table', @level1name = N'PIMS_LEASE', 
  	@level2type = N'Column', @level2name = N'TERM_START_DATE'
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_LEASE]
  	DROP COLUMN [IS_COMM_BLDG], [IS_OTHER_IMPROVEMENT], [IS_SUBJECT_TO_RTA], [LEASE_INITIATOR_TYPE_CODE], [LEASE_RESPONSIBILITY_TYPE_CODE], [RESPONSIBILITY_EFFECTIVE_DATE]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_ORGANIZATION
  PRINT N'Alter table dbo.PIMS_ORGANIZATION'
  GO
  ALTER TABLE [dbo].[PIMS_ORGANIZATION]
  	DROP COLUMN [ORGANIZATION_ALIAS]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_PROPERTY_IMPROVEMENT
  PRINT N'Alter table dbo.PIMS_PROPERTY_IMPROVEMENT'
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_IMPROVEMENT] ALTER COLUMN [STRUCTURE_SIZE] numeric(9,3) NULL
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_IMPROVEMENT]
  	ADD [PROPERTY_IMPROVEMENT_UOM_TYPE_CODE] nvarchar(20) NOT NULL
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_IMPROVEMENT]
  	DROP COLUMN [UNIT]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create procedure dbo.pims_error_handling
  PRINT N'Create procedure dbo.pims_error_handling'
  GO
  -- ............................................................................................
  
  
  -- --------------------------------------------------------------------------------------------
  -- Create procedure pims_error_handling 
  -- --------------------------------------------------------------------------------------------
  CREATE PROCEDURE [dbo].[pims_error_handling] AS 
    begin
      DECLARE @errmsg   nvarchar(2048),
        @severity tinyint,
        @state    tinyint,
        @errno    int,
        @proc     sysname,
        @lineno   int
             
      SELECT @errmsg = error_message(), @severity = error_severity(),
        @state  = error_state(), @errno = error_number(),
        @proc   = error_procedure(), @lineno = error_line()
  
      IF @errmsg NOT LIKE '***%'
        BEGIN
          SELECT @errmsg = '*** ' + coalesce(quotename(@proc), '<dynamic SQL>') + 
            ', Line ' + ltrim(str(@lineno)) + '. Errno ' + 
            ltrim(str(@errno)) + ': ' + @errmsg
        END
  
      RAISERROR('%s', @severity, @state, @errmsg)
    end
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_PROJECT_WORKFLOW_MODEL_HIST
  PRINT N'Alter table dbo.PIMS_PROJECT_WORKFLOW_MODEL_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_PROJECT_WORKFLOW_MODEL_HIST] DROP CONSTRAINT [DF__PIMS_PROJ___PROJ__6987862A]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROJECT_WORKFLOW_MODEL_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_PROJECT_WORKFLOW_MODEL_H_ID_SEQ]) FOR [_PROJECT_WORKFLOW_MODEL_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROJECT_WORKFLOW_MODEL_HIST] DROP CONSTRAINT [DF__PIMS_PROJ__EFFEC__6A7BAA63]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROJECT_WORKFLOW_MODEL_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_PROJECT_HIST
  PRINT N'Alter table dbo.PIMS_PROJECT_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_PROJECT_HIST] DROP CONSTRAINT [DF__PIMS_PROJ___PROJ__585CFA28]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROJECT_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_PROJECT_H_ID_SEQ]) FOR [_PROJECT_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROJECT_HIST] DROP CONSTRAINT [DF__PIMS_PROJ__EFFEC__59511E61]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROJECT_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_PROPERTY_EVALUATION_HIST
  PRINT N'Alter table dbo.PIMS_PROPERTY_EVALUATION_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_EVALUATION_HIST] DROP CONSTRAINT [DF__PIMS_PROP___PROP__74F938D6]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_EVALUATION_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_PROPERTY_EVALUATION_H_ID_SEQ]) FOR [_PROPERTY_EVALUATION_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_EVALUATION_HIST] DROP CONSTRAINT [DF__PIMS_PROP__EFFEC__75ED5D0F]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_EVALUATION_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_PROJECT_NOTE_HIST
  PRINT N'Alter table dbo.PIMS_PROJECT_NOTE_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_PROJECT_NOTE_HIST] DROP CONSTRAINT [DF__PIMS_PROJ___PROJ__5E15D37E]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROJECT_NOTE_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_PROJECT_NOTE_H_ID_SEQ]) FOR [_PROJECT_NOTE_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROJECT_NOTE_HIST] DROP CONSTRAINT [DF__PIMS_PROJ__EFFEC__5F09F7B7]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROJECT_NOTE_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_TASK_HIST
  PRINT N'Alter table dbo.PIMS_TASK_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_TASK_HIST] DROP CONSTRAINT [DF__PIMS_TASK___TASK__39A368DE]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_TASK_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_TASK_H_ID_SEQ]) FOR [_TASK_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_TASK_HIST] DROP CONSTRAINT [DF__PIMS_TASK__EFFEC__3A978D17]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_TASK_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_USER_ROLE_HIST
  PRINT N'Alter table dbo.PIMS_USER_ROLE_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_USER_ROLE_HIST] DROP CONSTRAINT [DF__PIMS_USER___USER__563FA78C]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_USER_ROLE_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_USER_ROLE_H_ID_SEQ]) FOR [_USER_ROLE_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_USER_ROLE_HIST] DROP CONSTRAINT [DF__PIMS_USER__EFFEC__5733CBC5]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_USER_ROLE_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_INSURANCE_HIST
  PRINT N'Alter table dbo.PIMS_INSURANCE_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_INSURANCE_HIST] DROP CONSTRAINT [DF__PIMS_INSU___INSU__1F247CCC]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_INSURANCE_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_INSURANCE_H_ID_SEQ]) FOR [_INSURANCE_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_INSURANCE_HIST] DROP CONSTRAINT [DF__PIMS_INSU__EFFEC__2018A105]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_INSURANCE_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_USER_ORGANIZATION_HIST
  PRINT N'Alter table dbo.PIMS_USER_ORGANIZATION_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_USER_ORGANIZATION_HIST] DROP CONSTRAINT [DF__PIMS_USER___USER__5086CE36]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_USER_ORGANIZATION_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_USER_ORGANIZATION_H_ID_SEQ]) FOR [_USER_ORGANIZATION_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_USER_ORGANIZATION_HIST] DROP CONSTRAINT [DF__PIMS_USER__EFFEC__517AF26F]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_USER_ORGANIZATION_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_ACTIVITY_MODEL_HIST
  PRINT N'Alter table dbo.PIMS_ACTIVITY_MODEL_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_ACTIVITY_MODEL_HIST] DROP CONSTRAINT [DF__PIMS_ACTI___ACTI__08411774]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ACTIVITY_MODEL_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_ACTIVITY_MODEL_H_ID_SEQ]) FOR [_ACTIVITY_MODEL_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ACTIVITY_MODEL_HIST] DROP CONSTRAINT [DF__PIMS_ACTI__EFFEC__09353BAD]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ACTIVITY_MODEL_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_PROPERTY_ORGANIZATION_HIST
  PRINT N'Alter table dbo.PIMS_PROPERTY_ORGANIZATION_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_ORGANIZATION_HIST] DROP CONSTRAINT [DF__PIMS_PROP___PROP__0BDC9E2E]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_ORGANIZATION_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_PROPERTY_ORGANIZATION_H_ID_SEQ]) FOR [_PROPERTY_ORGANIZATION_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_ORGANIZATION_HIST] DROP CONSTRAINT [DF__PIMS_PROP__EFFEC__0CD0C267]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_ORGANIZATION_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_ACCESS_REQUEST_ORGANIZATION_HIST
  PRINT N'Alter table dbo.PIMS_ACCESS_REQUEST_ORGANIZATION_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_ACCESS_REQUEST_ORGANIZATION_HIST] DROP CONSTRAINT [DF__PIMS_ACCE___ACCE__7CCF64C8]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ACCESS_REQUEST_ORGANIZATION_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_ACCESS_REQUEST_ORGANIZATION_H_ID_SEQ]) FOR [_ACCESS_REQUEST_ORGANIZATION_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ACCESS_REQUEST_ORGANIZATION_HIST] DROP CONSTRAINT [DF__PIMS_ACCE__EFFEC__7DC38901]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ACCESS_REQUEST_ORGANIZATION_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_LEASE_HIST
  PRINT N'Alter table dbo.PIMS_LEASE_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_HIST] DROP CONSTRAINT [DF__PIMS_LEAS___LEAS__24DD5622]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_LEASE_H_ID_SEQ]) FOR [_LEASE_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_HIST] DROP CONSTRAINT [DF__PIMS_LEAS__EFFEC__25D17A5B]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_HIST] ALTER COLUMN [RENEWAL_COUNT] smallint NOT NULL
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_HIST] DROP CONSTRAINT [_RENEWAL_TERM_MONTHS_DEF]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  EXEC sp_dropextendedproperty 
  	@name = N'MS_Description' , 
  	@level0type = N'Schema', @level0name = N'dbo', 
  	@level1type = N'Table', @level1name = N'PIMS_LEASE_HIST', 
  	@level2type = N'Column', @level2name = N'RENEWAL_TERM_MONTHS'
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_HIST]
  	ADD [TERM_EXPIRY_DATE] datetime NULL, 
  	[TERM_RENEWAL_DATE] datetime NULL, 
  	[TERM_START_DATE] datetime NULL
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_HIST]
  	DROP COLUMN [IS_COMM_BLDG], [IS_OTHER_IMPROVEMENT], [IS_SUBJECT_TO_RTA], [LEASE_INITIATOR_TYPE_CODE], [LEASE_RESPONSIBILITY_TYPE_CODE], [RESPONSIBILITY_EFFECTIVE_DATE]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_ROLE_CLAIM_HIST
  PRINT N'Alter table dbo.PIMS_ROLE_CLAIM_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_ROLE_CLAIM_HIST] DROP CONSTRAINT [DF__PIMS_ROLE___ROLE__22C00386]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ROLE_CLAIM_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_ROLE_CLAIM_H_ID_SEQ]) FOR [_ROLE_CLAIM_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ROLE_CLAIM_HIST] DROP CONSTRAINT [DF__PIMS_ROLE__EFFEC__23B427BF]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ROLE_CLAIM_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_SECURITY_DEPOSIT_RETURN_HIST
  PRINT N'Alter table dbo.PIMS_SECURITY_DEPOSIT_RETURN_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_SECURITY_DEPOSIT_RETURN_HIST] DROP CONSTRAINT [DF__PIMS_SECU___SECU__33EA8F88]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_SECURITY_DEPOSIT_RETURN_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_SECURITY_DEPOSIT_RETURN_H_ID_SEQ]) FOR [_SECURITY_DEPOSIT_RETURN_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_SECURITY_DEPOSIT_RETURN_HIST] DROP CONSTRAINT [DF__PIMS_SECU__EFFEC__34DEB3C1]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_SECURITY_DEPOSIT_RETURN_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_PROJECT_PROPERTY_HIST
  PRINT N'Alter table dbo.PIMS_PROJECT_PROPERTY_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_PROJECT_PROPERTY_HIST] DROP CONSTRAINT [DF__PIMS_PROJ___PROJ__63CEACD4]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROJECT_PROPERTY_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_PROJECT_PROPERTY_H_ID_SEQ]) FOR [_PROJECT_PROPERTY_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROJECT_PROPERTY_HIST] DROP CONSTRAINT [DF__PIMS_PROJ__EFFEC__64C2D10D]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROJECT_PROPERTY_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_SECURITY_DEPOSIT_HIST
  PRINT N'Alter table dbo.PIMS_SECURITY_DEPOSIT_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_SECURITY_DEPOSIT_HIST] DROP CONSTRAINT [DF__PIMS_SECU___SECU__2E31B632]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_SECURITY_DEPOSIT_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_SECURITY_DEPOSIT_H_ID_SEQ]) FOR [_SECURITY_DEPOSIT_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_SECURITY_DEPOSIT_HIST] DROP CONSTRAINT [DF__PIMS_SECU__EFFEC__2F25DA6B]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_SECURITY_DEPOSIT_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_LEASE_TENANT
  PRINT N'Alter table dbo.PIMS_LEASE_TENANT'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_TENANT]
  	DROP COLUMN [NOTE]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_PERSON_ORGANIZATION_HIST
  PRINT N'Alter table dbo.PIMS_PERSON_ORGANIZATION_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_PERSON_ORGANIZATION_HIST] DROP CONSTRAINT [DF__PIMS_PERS___PERS__52A420D2]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PERSON_ORGANIZATION_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_PERSON_ORGANIZATION_H_ID_SEQ]) FOR [_PERSON_ORGANIZATION_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PERSON_ORGANIZATION_HIST] DROP CONSTRAINT [DF__PIMS_PERS__EFFEC__5398450B]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PERSON_ORGANIZATION_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_WORKFLOW_MODEL_HIST
  PRINT N'Alter table dbo.PIMS_WORKFLOW_MODEL_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_WORKFLOW_MODEL_HIST] DROP CONSTRAINT [DF__PIMS_WORK___WORK__5BF880E2]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_WORKFLOW_MODEL_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_WORKFLOW_MODEL_H_ID_SEQ]) FOR [_WORKFLOW_MODEL_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_WORKFLOW_MODEL_HIST] DROP CONSTRAINT [DF__PIMS_WORK__EFFEC__5CECA51B]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_WORKFLOW_MODEL_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_TASK_TEMPLATE_ACTIVITY_MODEL_HIST
  PRINT N'Alter table dbo.PIMS_TASK_TEMPLATE_ACTIVITY_MODEL_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_TASK_TEMPLATE_ACTIVITY_MODEL_HIST] DROP CONSTRAINT [DF__PIMS_TASK___TASK__3F5C4234]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_TASK_TEMPLATE_ACTIVITY_MODEL_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_TASK_TEMPLATE_ACTIVITY_MODEL_H_ID_SEQ]) FOR [_TASK_TEMPLATE_ACTIVITY_MODEL_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_TASK_TEMPLATE_ACTIVITY_MODEL_HIST] DROP CONSTRAINT [DF__PIMS_TASK__EFFEC__4050666D]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_TASK_TEMPLATE_ACTIVITY_MODEL_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_CONTACT_METHOD_HIST
  PRINT N'Alter table dbo.PIMS_CONTACT_METHOD_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_CONTACT_METHOD_HIST] DROP CONSTRAINT [DF__PIMS_CONT___CONT__196BA376]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_CONTACT_METHOD_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_CONTACT_METHOD_H_ID_SEQ]) FOR [_CONTACT_METHOD_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_CONTACT_METHOD_HIST] DROP CONSTRAINT [DF__PIMS_CONT__EFFEC__1A5FC7AF]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_CONTACT_METHOD_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_PROPERTY_IMPROVEMENT_HIST
  PRINT N'Alter table dbo.PIMS_PROPERTY_IMPROVEMENT_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_IMPROVEMENT_HIST] DROP CONSTRAINT [DF__PIMS_PROP___PROP__006AEB82]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_IMPROVEMENT_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_PROPERTY_IMPROVEMENT_H_ID_SEQ]) FOR [_PROPERTY_IMPROVEMENT_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_IMPROVEMENT_HIST] DROP CONSTRAINT [DF__PIMS_PROP__EFFEC__015F0FBB]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_IMPROVEMENT_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_IMPROVEMENT_HIST] ALTER COLUMN [STRUCTURE_SIZE] numeric(18,0) NULL
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_IMPROVEMENT_HIST]
  	ADD [PROPERTY_IMPROVEMENT_UOM_TYPE_CODE] nvarchar(20) NOT NULL
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_IMPROVEMENT_HIST]
  	DROP COLUMN [UNIT]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_PROPERTY_SERVICE_FILE_HIST
  PRINT N'Alter table dbo.PIMS_PROPERTY_SERVICE_FILE_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_SERVICE_FILE_HIST] DROP CONSTRAINT [DF__PIMS_PROP___PROP__174E50DA]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_SERVICE_FILE_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_PROPERTY_SERVICE_FILE_H_ID_SEQ]) FOR [_PROPERTY_SERVICE_FILE_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_SERVICE_FILE_HIST] DROP CONSTRAINT [DF__PIMS_PROP__EFFEC__18427513]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_SERVICE_FILE_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_PROPERTY_ACTIVITY_HIST
  PRINT N'Alter table dbo.PIMS_PROPERTY_ACTIVITY_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_ACTIVITY_HIST] DROP CONSTRAINT [DF__PIMS_PROP___PROP__6F405F80]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_ACTIVITY_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_PROPERTY_ACTIVITY_H_ID_SEQ]) FOR [_PROPERTY_ACTIVITY_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_ACTIVITY_HIST] DROP CONSTRAINT [DF__PIMS_PROP__EFFEC__703483B9]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_ACTIVITY_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_ROLE_HIST
  PRINT N'Alter table dbo.PIMS_ROLE_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_ROLE_HIST] DROP CONSTRAINT [DF__PIMS_ROLE___ROLE__2878DCDC]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ROLE_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_ROLE_H_ID_SEQ]) FOR [_ROLE_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ROLE_HIST] DROP CONSTRAINT [DF__PIMS_ROLE__EFFEC__296D0115]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ROLE_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_TASK_TEMPLATE_HIST
  PRINT N'Alter table dbo.PIMS_TASK_TEMPLATE_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_TASK_TEMPLATE_HIST] DROP CONSTRAINT [DF__PIMS_TASK___TASK__45151B8A]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_TASK_TEMPLATE_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_TASK_TEMPLATE_H_ID_SEQ]) FOR [_TASK_TEMPLATE_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_TASK_TEMPLATE_HIST] DROP CONSTRAINT [DF__PIMS_TASK__EFFEC__46093FC3]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_TASK_TEMPLATE_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_PROPERTY_HIST
  PRINT N'Alter table dbo.PIMS_PROPERTY_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_HIST] DROP CONSTRAINT [DF__PIMS_PROP___PROP__7AB2122C]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_PROPERTY_H_ID_SEQ]) FOR [_PROPERTY_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_HIST] DROP CONSTRAINT [DF__PIMS_PROP__EFFEC__7BA63665]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_PERSON_HIST
  PRINT N'Alter table dbo.PIMS_PERSON_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_PERSON_HIST] DROP CONSTRAINT [DF__PIMS_PERS___PERS__4CEB477C]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PERSON_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_PERSON_H_ID_SEQ]) FOR [_PERSON_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PERSON_HIST] DROP CONSTRAINT [DF__PIMS_PERS__EFFEC__4DDF6BB5]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PERSON_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PERSON_HIST]
  	DROP COLUMN [PREFERRED_NAME]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_PROPERTY_PROPERTY_SERVICE_FILE_HIST
  PRINT N'Alter table dbo.PIMS_PROPERTY_PROPERTY_SERVICE_FILE_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_PROPERTY_SERVICE_FILE_HIST] DROP CONSTRAINT [DF__PIMS_PROP___PROP__11957784]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_PROPERTY_SERVICE_FILE_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_PROPERTY_PROPERTY_SERVICE_FILE_H_ID_SEQ]) FOR [_PROPERTY_PROPERTY_SERVICE_FILE_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_PROPERTY_SERVICE_FILE_HIST] DROP CONSTRAINT [DF__PIMS_PROP__EFFEC__12899BBD]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_PROPERTY_SERVICE_FILE_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_PROPERTY_LEASE_HIST
  PRINT N'Alter table dbo.PIMS_PROPERTY_LEASE_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_LEASE_HIST] DROP CONSTRAINT [DF__PIMS_PROP___PROP__0623C4D8]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_LEASE_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_PROPERTY_LEASE_H_ID_SEQ]) FOR [_PROPERTY_LEASE_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_LEASE_HIST] DROP CONSTRAINT [DF__PIMS_PROP__EFFEC__0717E911]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_LEASE_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_PROPERTY_TAX_HIST
  PRINT N'Alter table dbo.PIMS_PROPERTY_TAX_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_TAX_HIST] DROP CONSTRAINT [DF__PIMS_PROP___PROP__1D072A30]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_TAX_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_PROPERTY_TAX_H_ID_SEQ]) FOR [_PROPERTY_TAX_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_TAX_HIST] DROP CONSTRAINT [DF__PIMS_PROP__EFFEC__1DFB4E69]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_TAX_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_ADDRESS_HIST
  PRINT N'Alter table dbo.PIMS_ADDRESS_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_ADDRESS_HIST] DROP CONSTRAINT [DF__PIMS_ADDR___ADDR__0DF9F0CA]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ADDRESS_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_ADDRESS_H_ID_SEQ]) FOR [_ADDRESS_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ADDRESS_HIST] DROP CONSTRAINT [DF__PIMS_ADDR__EFFEC__0EEE1503]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ADDRESS_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ADDRESS_HIST]
  	DROP COLUMN [COMMENT]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_USER_HIST
  PRINT N'Alter table dbo.PIMS_USER_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_USER_HIST] DROP CONSTRAINT [DF__PIMS_USER___USER__4ACDF4E0]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_USER_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_USER_H_ID_SEQ]) FOR [_USER_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_USER_HIST] DROP CONSTRAINT [DF__PIMS_USER__EFFEC__4BC21919]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_USER_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_ACTIVITY_HIST
  PRINT N'Alter table dbo.PIMS_ACTIVITY_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_ACTIVITY_HIST] DROP CONSTRAINT [DF__PIMS_ACTI___ACTI__02883E1E]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ACTIVITY_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_ACTIVITY_H_ID_SEQ]) FOR [_ACTIVITY_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ACTIVITY_HIST] DROP CONSTRAINT [DF__PIMS_ACTI__EFFEC__037C6257]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ACTIVITY_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_CLAIM_HIST
  PRINT N'Alter table dbo.PIMS_CLAIM_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_CLAIM_HIST] DROP CONSTRAINT [DF__PIMS_CLAI___CLAI__13B2CA20]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_CLAIM_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_CLAIM_H_ID_SEQ]) FOR [_CLAIM_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_CLAIM_HIST] DROP CONSTRAINT [DF__PIMS_CLAI__EFFEC__14A6EE59]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_CLAIM_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_ORGANIZATION_HIST
  PRINT N'Alter table dbo.PIMS_ORGANIZATION_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_ORGANIZATION_HIST] DROP CONSTRAINT [DF__PIMS_ORGA___ORGA__47326E26]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ORGANIZATION_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_ORGANIZATION_H_ID_SEQ]) FOR [_ORGANIZATION_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ORGANIZATION_HIST] DROP CONSTRAINT [DF__PIMS_ORGA__EFFEC__4826925F]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ORGANIZATION_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ORGANIZATION_HIST]
  	DROP COLUMN [ORGANIZATION_ALIAS]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_ACCESS_REQUEST_HIST
  PRINT N'Alter table dbo.PIMS_ACCESS_REQUEST_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_ACCESS_REQUEST_HIST] DROP CONSTRAINT [DF__PIMS_ACCE___ACCE__77168B72]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ACCESS_REQUEST_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_ACCESS_REQUEST_H_ID_SEQ]) FOR [_ACCESS_REQUEST_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ACCESS_REQUEST_HIST] DROP CONSTRAINT [DF__PIMS_ACCE__EFFEC__780AAFAB]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_ACCESS_REQUEST_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Alter table dbo.PIMS_LEASE_TENANT_HIST
  PRINT N'Alter table dbo.PIMS_LEASE_TENANT_HIST'
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_TENANT_HIST] DROP CONSTRAINT [DF__PIMS_LEAS___LEAS__3BC0BB7A]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_TENANT_HIST] ADD DEFAULT (NEXT VALUE FOR [PIMS_LEASE_TENANT_H_ID_SEQ]) FOR [_LEASE_TENANT_HIST_ID]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_TENANT_HIST] DROP CONSTRAINT [DF__PIMS_LEAS__EFFEC__3CB4DFB3]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_TENANT_HIST] ADD DEFAULT (getutcdate()) FOR [EFFECTIVE_DATE_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  ALTER TABLE [dbo].[PIMS_LEASE_TENANT_HIST]
  	DROP COLUMN [NOTE]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create view dbo.PIMS_PROPERTY_BOUNDARY_VW
  PRINT N'Create view dbo.PIMS_PROPERTY_BOUNDARY_VW'
  GO
  /* ---------------------------------------------------------------------- */
  /* Add views                                                              */
  /* ---------------------------------------------------------------------- */
  
  /* ---------------------------------------------------------------------- */
  /* Add views                                                              */
  /* ---------------------------------------------------------------------- */
  
  CREATE VIEW [dbo].[PIMS_PROPERTY_BOUNDARY_VW] AS
  SELECT PROP.PROPERTY_ID
       , PROP.PID
       , PROP.PIN
       , PROP.PROPERTY_TYPE_CODE
       , PROP.PROPERTY_STATUS_TYPE_CODE
       , PROP.PROPERTY_DATA_SOURCE_TYPE_CODE
       , PROP.PROPERTY_DATA_SOURCE_EFFECTIVE_DATE
       , PROP.PROPERTY_CLASSIFICATION_TYPE_CODE
       , PROP.PROPERTY_TENURE_TYPE_CODE
       , ADDR.STREET_ADDRESS_1
       , ADDR.STREET_ADDRESS_2
       , ADDR.STREET_ADDRESS_3
       , ADDR.MUNICIPALITY_NAME
       , ADDR.POSTAL_CODE
       , PROV.PROVINCE_STATE_CODE
       , PROV.DESCRIPTION AS PROVINCE_NAME
       , CNTY.COUNTRY_CODE
       , CNTY.DESCRIPTION AS COUNTRY_NAME
       , PROP.NAME
       , PROP.DESCRIPTION
       , PROP.ADDRESS_ID
       , PROP.REGION_CODE
       , PROP.DISTRICT_CODE
       , PROP.BOUNDARY AS GEOMETRY
       , PROP.PROPERTY_AREA_UNIT_TYPE_CODE
       , PROP.LAND_AREA
       , PROP.LAND_LEGAL_DESCRIPTION
       , PROP.ENCUMBRANCE_REASON
       , PROP.IS_SENSITIVE
       , PROP.IS_OWNED
       , PROP.IS_PROPERTY_OF_INTEREST
       , PROP.IS_VISIBLE_TO_OTHER_AGENCIES
       , PROP.ZONING,ZONING_POTENTIAL
  FROM   PIMS_PROPERTY       PROP                                                    INNER JOIN
         PIMS_ADDRESS        ADDR ON ADDR.ADDRESS_ID        = PROP.ADDRESS_ID        INNER JOIN
         PIMS_PROVINCE_STATE PROV ON PROV.PROVINCE_STATE_ID = ADDR.PROVINCE_STATE_ID INNER JOIN
         PIMS_COUNTRY        CNTY ON CNTY.COUNTRY_ID        = ADDR.COUNTRY_ID
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create view dbo.PIMS_PROPERTY_LOCATION_VW
  PRINT N'Create view dbo.PIMS_PROPERTY_LOCATION_VW'
  GO
  CREATE VIEW [dbo].[PIMS_PROPERTY_LOCATION_VW] AS
  SELECT PROP.PROPERTY_ID              
       , PROP.PID                
       , PROP.PIN                   
       , PROP.PROPERTY_TYPE_CODE
       , PROP.PROPERTY_STATUS_TYPE_CODE
       , PROP.PROPERTY_DATA_SOURCE_TYPE_CODE
       , PROP.PROPERTY_DATA_SOURCE_EFFECTIVE_DATE
       , PROP.PROPERTY_CLASSIFICATION_TYPE_CODE
       , PROP.PROPERTY_TENURE_TYPE_CODE
       , ADDR.STREET_ADDRESS_1
       , ADDR.STREET_ADDRESS_2
       , ADDR.STREET_ADDRESS_3
       , ADDR.MUNICIPALITY_NAME
       , ADDR.POSTAL_CODE      
       , PROV.PROVINCE_STATE_CODE
       , PROV.DESCRIPTION AS PROVINCE_NAME
       , CNTY.COUNTRY_CODE
       , CNTY.DESCRIPTION AS COUNTRY_NAME
       , PROP.NAME
       , PROP.DESCRIPTION
       , PROP.ADDRESS_ID                 
       , PROP.REGION_CODE
       , PROP.DISTRICT_CODE
       , PROP.LOCATION AS GEOMETRY
       , PROP.PROPERTY_AREA_UNIT_TYPE_CODE
       , PROP.LAND_AREA
       , PROP.LAND_LEGAL_DESCRIPTION
       , PROP.ENCUMBRANCE_REASON
       , PROP.IS_SENSITIVE
       , PROP.IS_OWNED
       , PROP.IS_PROPERTY_OF_INTEREST
       , PROP.IS_VISIBLE_TO_OTHER_AGENCIES
       , PROP.ZONING,ZONING_POTENTIAL
  FROM   PIMS_PROPERTY       PROP                                                    INNER JOIN
         PIMS_ADDRESS        ADDR ON ADDR.ADDRESS_ID        = PROP.ADDRESS_ID        INNER JOIN
         PIMS_PROVINCE_STATE PROV ON PROV.PROVINCE_STATE_ID = ADDR.PROVINCE_STATE_ID INNER JOIN
         PIMS_COUNTRY        CNTY ON CNTY.COUNTRY_ID        = ADDR.COUNTRY_ID
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create index dbo.PIMPRV_PROPERTY_IMPROVEMENT_UOM_TYPE_CODE_IDX
  PRINT N'Create index dbo.PIMPRV_PROPERTY_IMPROVEMENT_UOM_TYPE_CODE_IDX'
  GO
  CREATE NONCLUSTERED INDEX [PIMPRV_PROPERTY_IMPROVEMENT_UOM_TYPE_CODE_IDX]
  	ON [dbo].[PIMS_PROPERTY_IMPROVEMENT]([PROPERTY_IMPROVEMENT_UOM_TYPE_CODE])
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_LEASE_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_LEASE_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_LEASE_I_S_I_TR] ON PIMS_LEASE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_LEASE ("LEASE_ID",
        "MOTI_NAME_ID",
        "LEASE_PAY_RVBL_TYPE_CODE",
        "LEASE_LICENSE_TYPE_CODE",
        "LEASE_CATEGORY_TYPE_CODE",
        "LEASE_PURPOSE_TYPE_CODE",
        "LEASE_PROGRAM_TYPE_CODE",
        "LEASE_PMT_FREQ_TYPE_CODE",
        "LEASE_PURPOSE_OTHER_DESC",
        "L_FILE_NO",
        "TFA_FILE_NO",
        "PS_FILE_NO",
        "LEASE_DESCRIPTION",
        "LEASE_NOTES",
        "ORIG_START_DATE",
        "ORIG_EXPIRY_DATE",
        "IS_ORIG_EXPIRY_REQUIRED",
        "TERM_START_DATE",
        "TERM_EXPIRY_DATE",
        "TERM_RENEWAL_DATE",
        "INCLUDED_RENEWALS",
        "RENEWAL_COUNT",
        "RENEWAL_TERM_MONTHS",
        "LEASE_AMOUNT",
        "INSPECTION_DATE",
        "INSPECTION_NOTES",
        "IS_EXPIRED",
        "HAS_PHYSICAL_FILE",
        "HAS_DIGITAL_FILE",
        "HAS_PHYSICIAL_LICENSE",
        "HAS_DIGITAL_LICENSE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "LEASE_ID",
        "MOTI_NAME_ID",
        "LEASE_PAY_RVBL_TYPE_CODE",
        "LEASE_LICENSE_TYPE_CODE",
        "LEASE_CATEGORY_TYPE_CODE",
        "LEASE_PURPOSE_TYPE_CODE",
        "LEASE_PROGRAM_TYPE_CODE",
        "LEASE_PMT_FREQ_TYPE_CODE",
        "LEASE_PURPOSE_OTHER_DESC",
        "L_FILE_NO",
        "TFA_FILE_NO",
        "PS_FILE_NO",
        "LEASE_DESCRIPTION",
        "LEASE_NOTES",
        "ORIG_START_DATE",
        "ORIG_EXPIRY_DATE",
        "IS_ORIG_EXPIRY_REQUIRED",
        "TERM_START_DATE",
        "TERM_EXPIRY_DATE",
        "TERM_RENEWAL_DATE",
        "INCLUDED_RENEWALS",
        "RENEWAL_COUNT",
        "RENEWAL_TERM_MONTHS",
        "LEASE_AMOUNT",
        "INSPECTION_DATE",
        "INSPECTION_NOTES",
        "IS_EXPIRED",
        "HAS_PHYSICAL_FILE",
        "HAS_DIGITAL_FILE",
        "HAS_PHYSICIAL_LICENSE",
        "HAS_DIGITAL_LICENSE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PROJNT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PROJNT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PROJNT_I_S_I_TR] ON PIMS_PROJECT_NOTE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROJECT_NOTE ("PROJECT_NOTE_ID",
        "PROJECT_ID",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USER_DIRECTORY",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USERID",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USERID",
        "CONCURRENCY_CONTROL_NUMBER")
      select "PROJECT_NOTE_ID",
        "PROJECT_ID",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USER_DIRECTORY",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USERID",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USERID",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_USERRL_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_USERRL_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_USERRL_I_S_I_TR] ON PIMS_USER_ROLE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_USER_ROLE ("USER_ROLE_ID",
        "USER_ID",
        "ROLE_ID",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "USER_ROLE_ID",
        "USER_ID",
        "ROLE_ID",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_CNTMTT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_CNTMTT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_CNTMTT_I_S_I_TR] ON PIMS_CONTACT_METHOD_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_CONTACT_METHOD_TYPE ("CONTACT_METHOD_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "CONTACT_METHOD_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRWKMD_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_PRWKMD_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRWKMD_A_S_IUD_TR] ON PIMS_PROJECT_WORKFLOW_MODEL FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_PROJECT_WORKFLOW_MODEL_HIST set END_DATE_HIST = @curr_date where PROJECT_WORKFLOW_MODEL_ID in (select PROJECT_WORKFLOW_MODEL_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_PROJECT_WORKFLOW_MODEL_HIST ([PROJECT_WORKFLOW_MODEL_ID], [PROJECT_ID], [WORKFLOW_MODEL_ID], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _PROJECT_WORKFLOW_MODEL_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [PROJECT_WORKFLOW_MODEL_ID], [PROJECT_ID], [WORKFLOW_MODEL_ID], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_PROJECT_WORKFLOW_MODEL_H_ID_SEQ]) as [_PROJECT_WORKFLOW_MODEL_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ADUSGT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_ADUSGT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ADUSGT_I_S_U_TR] ON PIMS_ADDRESS_USAGE_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.ADDRESS_USAGE_TYPE_CODE = deleted.ADDRESS_USAGE_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_ADDRESS_USAGE_TYPE
      set "ADDRESS_USAGE_TYPE_CODE" = inserted."ADDRESS_USAGE_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_ADDRESS_USAGE_TYPE
      inner join inserted
      on (PIMS_ADDRESS_USAGE_TYPE.ADDRESS_USAGE_TYPE_CODE = inserted.ADDRESS_USAGE_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PROJCT_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_PROJCT_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PROJCT_A_S_IUD_TR] ON PIMS_PROJECT FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_PROJECT_HIST set END_DATE_HIST = @curr_date where PROJECT_ID in (select PROJECT_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_PROJECT_HIST ([PROJECT_ID], [PROJECT_TYPE_CODE], [PROJECT_STATUS_TYPE_CODE], [PROJECT_RISK_TYPE_CODE], [PROJECT_TIER_TYPE_CODE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _PROJECT_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [PROJECT_ID], [PROJECT_TYPE_CODE], [PROJECT_STATUS_TYPE_CODE], [PROJECT_RISK_TYPE_CODE], [PROJECT_TIER_TYPE_CODE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_PROJECT_H_ID_SEQ]) as [_PROJECT_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_DSTRCT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_DSTRCT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_DSTRCT_I_S_I_TR] ON PIMS_DISTRICT INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_DISTRICT ("DISTRICT_CODE",
        "REGION_CODE",
        "DISTRICT_NAME",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "DISTRICT_CODE",
        "REGION_CODE",
        "DISTRICT_NAME",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PROJCT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PROJCT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PROJCT_I_S_U_TR] ON PIMS_PROJECT INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROJECT_ID = deleted.PROJECT_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROJECT
      set "PROJECT_ID" = inserted."PROJECT_ID",
        "PROJECT_TYPE_CODE" = inserted."PROJECT_TYPE_CODE",
        "PROJECT_STATUS_TYPE_CODE" = inserted."PROJECT_STATUS_TYPE_CODE",
        "PROJECT_RISK_TYPE_CODE" = inserted."PROJECT_RISK_TYPE_CODE",
        "PROJECT_TIER_TYPE_CODE" = inserted."PROJECT_TIER_TYPE_CODE",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROJECT
      inner join inserted
      on (PIMS_PROJECT.PROJECT_ID = inserted.PROJECT_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPTAX_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PRPTAX_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPTAX_I_S_I_TR] ON PIMS_PROPERTY_TAX INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROPERTY_TAX ("PROPERTY_TAX_ID",
        "PROPERTY_ID",
        "PROPERTY_TAX_REMIT_TYPE_CODE",
        "TAX_FOLIO_NO",
        "PAYMENT_AMOUNT",
        "LAST_PAYMENT_DATE",
        "PAYMENT_NOTES",
        "BCTFA_NOTIFICATION_DATE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "PROPERTY_TAX_ID",
        "PROPERTY_ID",
        "PROPERTY_TAX_REMIT_TYPE_CODE",
        "TAX_FOLIO_NO",
        "PAYMENT_AMOUNT",
        "LAST_PAYMENT_DATE",
        "PAYMENT_NOTES",
        "BCTFA_NOTIFICATION_DATE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPEVL_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_PRPEVL_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPEVL_A_S_IUD_TR] ON PIMS_PROPERTY_EVALUATION FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_PROPERTY_EVALUATION_HIST set END_DATE_HIST = @curr_date where PROPERTY_EVALUATION_ID in (select PROPERTY_EVALUATION_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_PROPERTY_EVALUATION_HIST ([PROPERTY_EVALUATION_ID], [PROPERTY_ID], [EVALUATION_DATE], [KEY], [VALUE], [NOTE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _PROPERTY_EVALUATION_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [PROPERTY_EVALUATION_ID], [PROPERTY_ID], [EVALUATION_DATE], [KEY], [VALUE], [NOTE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_PROPERTY_EVALUATION_H_ID_SEQ]) as [_PROPERTY_EVALUATION_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PTRMTT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PTRMTT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PTRMTT_I_S_U_TR] ON PIMS_PROPERTY_TAX_REMIT_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROPERTY_TAX_REMIT_TYPE_CODE = deleted.PROPERTY_TAX_REMIT_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROPERTY_TAX_REMIT_TYPE
      set "PROPERTY_TAX_REMIT_TYPE_CODE" = inserted."PROPERTY_TAX_REMIT_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROPERTY_TAX_REMIT_TYPE
      inner join inserted
      on (PIMS_PROPERTY_TAX_REMIT_TYPE.PROPERTY_TAX_REMIT_TYPE_CODE = inserted.PROPERTY_TAX_REMIT_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PIMPRT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PIMPRT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PIMPRT_I_S_U_TR] ON PIMS_PROPERTY_IMPROVEMENT_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROPERTY_IMPROVEMENT_TYPE_CODE = deleted.PROPERTY_IMPROVEMENT_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROPERTY_IMPROVEMENT_TYPE
      set "PROPERTY_IMPROVEMENT_TYPE_CODE" = inserted."PROPERTY_IMPROVEMENT_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROPERTY_IMPROVEMENT_TYPE
      inner join inserted
      on (PIMS_PROPERTY_IMPROVEMENT_TYPE.PROPERTY_IMPROVEMENT_TYPE_CODE = inserted.PROPERTY_IMPROVEMENT_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ARUNIT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_ARUNIT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ARUNIT_I_S_U_TR] ON PIMS_AREA_UNIT_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.AREA_UNIT_TYPE_CODE = deleted.AREA_UNIT_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_AREA_UNIT_TYPE
      set "AREA_UNIT_TYPE_CODE" = inserted."AREA_UNIT_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_AREA_UNIT_TYPE
      inner join inserted
      on (PIMS_AREA_UNIT_TYPE.AREA_UNIT_TYPE_CODE = inserted.AREA_UNIT_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPEVL_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PRPEVL_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPEVL_I_S_U_TR] ON PIMS_PROPERTY_EVALUATION INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROPERTY_EVALUATION_ID = deleted.PROPERTY_EVALUATION_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROPERTY_EVALUATION
      set "PROPERTY_EVALUATION_ID" = inserted."PROPERTY_EVALUATION_ID",
        "PROPERTY_ID" = inserted."PROPERTY_ID",
        "EVALUATION_DATE" = inserted."EVALUATION_DATE",
        "KEY" = inserted."KEY",
        "VALUE" = inserted."VALUE",
        "NOTE" = inserted."NOTE",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROPERTY_EVALUATION
      inner join inserted
      on (PIMS_PROPERTY_EVALUATION.PROPERTY_EVALUATION_ID = inserted.PROPERTY_EVALUATION_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ROLCLM_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_ROLCLM_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ROLCLM_I_S_I_TR] ON PIMS_ROLE_CLAIM INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_ROLE_CLAIM ("ROLE_CLAIM_ID",
        "ROLE_ID",
        "CLAIM_ID",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "ROLE_CLAIM_ID",
        "ROLE_ID",
        "CLAIM_ID",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_USER_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_USER_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_USER_I_S_I_TR] ON PIMS_USER INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_USER ("USER_ID",
        "PERSON_ID",
        "BUSINESS_IDENTIFIER_VALUE",
        "GUID_IDENTIFIER_VALUE",
        "POSITION",
        "NOTE",
        "LAST_LOGIN",
        "APPROVED_BY_ID",
        "ISSUE_DATE",
        "EXPIRY_DATE",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "USER_ID",
        "PERSON_ID",
        "BUSINESS_IDENTIFIER_VALUE",
        "GUID_IDENTIFIER_VALUE",
        "POSITION",
        "NOTE",
        "LAST_LOGIN",
        "APPROVED_BY_ID",
        "ISSUE_DATE",
        "EXPIRY_DATE",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPSVC_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PRPSVC_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPSVC_I_S_U_TR] ON PIMS_PROPERTY_SERVICE_FILE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROPERTY_SERVICE_FILE_ID = deleted.PROPERTY_SERVICE_FILE_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROPERTY_SERVICE_FILE
      set "PROPERTY_SERVICE_FILE_ID" = inserted."PROPERTY_SERVICE_FILE_ID",
        "PROPERTY_SERVICE_FILE_TYPE_CODE" = inserted."PROPERTY_SERVICE_FILE_TYPE_CODE",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROPERTY_SERVICE_FILE
      inner join inserted
      on (PIMS_PROPERTY_SERVICE_FILE.PROPERTY_SERVICE_FILE_ID = inserted.PROPERTY_SERVICE_FILE_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_SDRTRN_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_SDRTRN_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_SDRTRN_I_S_I_TR] ON PIMS_SECURITY_DEPOSIT_RETURN INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_SECURITY_DEPOSIT_RETURN ("SECURITY_DEPOSIT_RETURN_ID",
        "LEASE_ID",
        "SECURITY_DEPOSIT_TYPE_CODE",
        "TERMINATION_DATE",
        "DEPOSIT_TOTAL",
        "CLAIMS_AGAINST",
        "RETURN_AMOUNT",
        "RETURN_DATE",
        "CHEQUE_NUMBER",
        "PAYEE_NAME",
        "PAYEE_ADDRESS",
        "TERMINATION_NOTE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "SECURITY_DEPOSIT_RETURN_ID",
        "LEASE_ID",
        "SECURITY_DEPOSIT_TYPE_CODE",
        "TERMINATION_DATE",
        "DEPOSIT_TOTAL",
        "CLAIMS_AGAINST",
        "RETURN_AMOUNT",
        "RETURN_DATE",
        "CHEQUE_NUMBER",
        "PAYEE_NAME",
        "PAYEE_ADDRESS",
        "TERMINATION_NOTE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PTRMTT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PTRMTT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PTRMTT_I_S_I_TR] ON PIMS_PROPERTY_TAX_REMIT_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROPERTY_TAX_REMIT_TYPE ("PROPERTY_TAX_REMIT_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "PROPERTY_TAX_REMIT_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_INSPAY_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_INSPAY_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_INSPAY_I_S_I_TR] ON PIMS_INSURANCE_PAYEE_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_INSURANCE_PAYEE_TYPE ("INSURANCE_PAYEE_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "INSURANCE_PAYEE_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_REGION_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_REGION_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_REGION_I_S_U_TR] ON PIMS_REGION INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.REGION_CODE = deleted.REGION_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_REGION
      set "REGION_CODE" = inserted."REGION_CODE",
        "REGION_NAME" = inserted."REGION_NAME",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_REGION
      inner join inserted
      on (PIMS_REGION.REGION_CODE = inserted.REGION_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ROLE_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_ROLE_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ROLE_I_S_I_TR] ON PIMS_ROLE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_ROLE ("ROLE_ID",
        "ROLE_UID",
        "KEYCLOAK_GROUP_ID",
        "NAME",
        "DESCRIPTION",
        "IS_PUBLIC",
        "IS_DISABLED",
        "SORT_ORDER",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "ROLE_ID",
        "ROLE_UID",
        "KEYCLOAK_GROUP_ID",
        "NAME",
        "DESCRIPTION",
        "IS_PUBLIC",
        "IS_DISABLED",
        "SORT_ORDER",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_DSTRCT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_DSTRCT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_DSTRCT_I_S_U_TR] ON PIMS_DISTRICT INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.DISTRICT_CODE = deleted.DISTRICT_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_DISTRICT
      set "DISTRICT_CODE" = inserted."DISTRICT_CODE",
        "REGION_CODE" = inserted."REGION_CODE",
        "DISTRICT_NAME" = inserted."DISTRICT_NAME",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_DISTRICT
      inner join inserted
      on (PIMS_DISTRICT.DISTRICT_CODE = inserted.DISTRICT_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPTAX_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PRPTAX_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPTAX_I_S_U_TR] ON PIMS_PROPERTY_TAX INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROPERTY_TAX_ID = deleted.PROPERTY_TAX_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROPERTY_TAX
      set "PROPERTY_TAX_ID" = inserted."PROPERTY_TAX_ID",
        "PROPERTY_ID" = inserted."PROPERTY_ID",
        "PROPERTY_TAX_REMIT_TYPE_CODE" = inserted."PROPERTY_TAX_REMIT_TYPE_CODE",
        "TAX_FOLIO_NO" = inserted."TAX_FOLIO_NO",
        "PAYMENT_AMOUNT" = inserted."PAYMENT_AMOUNT",
        "LAST_PAYMENT_DATE" = inserted."LAST_PAYMENT_DATE",
        "PAYMENT_NOTES" = inserted."PAYMENT_NOTES",
        "BCTFA_NOTIFICATION_DATE" = inserted."BCTFA_NOTIFICATION_DATE",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROPERTY_TAX
      inner join inserted
      on (PIMS_PROPERTY_TAX.PROPERTY_TAX_ID = inserted.PROPERTY_TAX_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PROJNT_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_PROJNT_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PROJNT_A_S_IUD_TR] ON PIMS_PROJECT_NOTE FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_PROJECT_NOTE_HIST set END_DATE_HIST = @curr_date where PROJECT_NOTE_ID in (select PROJECT_NOTE_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_PROJECT_NOTE_HIST ([PROJECT_NOTE_ID], [PROJECT_ID], [APP_CREATE_TIMESTAMP], [APP_CREATE_USER_DIRECTORY], [APP_CREATE_USER_GUID], [APP_CREATE_USERID], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USER_DIRECTORY], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USERID], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _PROJECT_NOTE_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [PROJECT_NOTE_ID], [PROJECT_ID], [APP_CREATE_TIMESTAMP], [APP_CREATE_USER_DIRECTORY], [APP_CREATE_USER_GUID], [APP_CREATE_USERID], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USER_DIRECTORY], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USERID], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_PROJECT_NOTE_H_ID_SEQ]) as [_PROJECT_NOTE_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_TSKTAM_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_TSKTAM_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_TSKTAM_I_S_I_TR] ON PIMS_TASK_TEMPLATE_ACTIVITY_MODEL INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_TASK_TEMPLATE_ACTIVITY_MODEL ("TASK_TEMPLATE_ACTIVITY_MODEL_ID",
        "TASK_TEMPLATE_ID",
        "ACTIVITY_MODEL_ID",
        "IS_MANDATORY",
        "IMPLEMENTATION_ORDER",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "TASK_TEMPLATE_ACTIVITY_MODEL_ID",
        "TASK_TEMPLATE_ID",
        "ACTIVITY_MODEL_ID",
        "IS_MANDATORY",
        "IMPLEMENTATION_ORDER",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_TASK_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_TASK_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_TASK_A_S_IUD_TR] ON PIMS_TASK FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_TASK_HIST set END_DATE_HIST = @curr_date where TASK_ID in (select TASK_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_TASK_HIST ([TASK_ID], [TASK_TEMPLATE_ID], [ACTIVITY_ID], [USER_ID], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _TASK_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [TASK_ID], [TASK_TEMPLATE_ID], [ACTIVITY_ID], [USER_ID], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_TASK_H_ID_SEQ]) as [_TASK_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ADDRSS_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_ADDRSS_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ADDRSS_I_S_U_TR] ON PIMS_ADDRESS INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.ADDRESS_ID = deleted.ADDRESS_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_ADDRESS
      set "ADDRESS_ID" = inserted."ADDRESS_ID",
        "ADDRESS_USAGE_TYPE_CODE" = inserted."ADDRESS_USAGE_TYPE_CODE",
        "REGION_CODE" = inserted."REGION_CODE",
        "DISTRICT_CODE" = inserted."DISTRICT_CODE",
        "PROVINCE_STATE_ID" = inserted."PROVINCE_STATE_ID",
        "COUNTRY_ID" = inserted."COUNTRY_ID",
        "STREET_ADDRESS_1" = inserted."STREET_ADDRESS_1",
        "STREET_ADDRESS_2" = inserted."STREET_ADDRESS_2",
        "STREET_ADDRESS_3" = inserted."STREET_ADDRESS_3",
        "MUNICIPALITY_NAME" = inserted."MUNICIPALITY_NAME",
        "POSTAL_CODE" = inserted."POSTAL_CODE",
        "LATITUDE" = inserted."LATITUDE",
        "LONGITUDE" = inserted."LONGITUDE",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_ADDRESS
      inner join inserted
      on (PIMS_ADDRESS.ADDRESS_ID = inserted.ADDRESS_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PERORG_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PERORG_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PERORG_I_S_I_TR] ON PIMS_PERSON_ORGANIZATION INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PERSON_ORGANIZATION ("PERSON_ORGANIZATION_ID",
        "PERSON_ID",
        "ORGANIZATION_ID",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "PERSON_ORGANIZATION_ID",
        "PERSON_ID",
        "ORGANIZATION_ID",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_USERRL_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_USERRL_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_USERRL_I_S_U_TR] ON PIMS_USER_ROLE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.USER_ROLE_ID = deleted.USER_ROLE_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_USER_ROLE
      set "USER_ROLE_ID" = inserted."USER_ROLE_ID",
        "USER_ID" = inserted."USER_ID",
        "ROLE_ID" = inserted."ROLE_ID",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_USER_ROLE
      inner join inserted
      on (PIMS_USER_ROLE.USER_ROLE_ID = inserted.USER_ROLE_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_CNTMTT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_CNTMTT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_CNTMTT_I_S_U_TR] ON PIMS_CONTACT_METHOD_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.CONTACT_METHOD_TYPE_CODE = deleted.CONTACT_METHOD_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_CONTACT_METHOD_TYPE
      set "CONTACT_METHOD_TYPE_CODE" = inserted."CONTACT_METHOD_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_CONTACT_METHOD_TYPE
      inner join inserted
      on (PIMS_CONTACT_METHOD_TYPE.CONTACT_METHOD_TYPE_CODE = inserted.CONTACT_METHOD_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_USERRL_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_USERRL_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_USERRL_A_S_IUD_TR] ON PIMS_USER_ROLE FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_USER_ROLE_HIST set END_DATE_HIST = @curr_date where USER_ROLE_ID in (select USER_ROLE_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_USER_ROLE_HIST ([USER_ROLE_ID], [USER_ID], [ROLE_ID], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _USER_ROLE_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [USER_ROLE_ID], [USER_ID], [ROLE_ID], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_USER_ROLE_H_ID_SEQ]) as [_USER_ROLE_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ADUSGT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_ADUSGT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ADUSGT_I_S_I_TR] ON PIMS_ADDRESS_USAGE_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_ADDRESS_USAGE_TYPE ("ADDRESS_USAGE_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "ADDRESS_USAGE_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPTNR_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PRPTNR_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPTNR_I_S_U_TR] ON PIMS_PROPERTY_TENURE_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROPERTY_TENURE_TYPE_CODE = deleted.PROPERTY_TENURE_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROPERTY_TENURE_TYPE
      set "PROPERTY_TENURE_TYPE_CODE" = inserted."PROPERTY_TENURE_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROPERTY_TENURE_TYPE
      inner join inserted
      on (PIMS_PROPERTY_TENURE_TYPE.PROPERTY_TENURE_TYPE_CODE = inserted.PROPERTY_TENURE_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ADDRSS_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_ADDRSS_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ADDRSS_I_S_I_TR] ON PIMS_ADDRESS INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_ADDRESS ("ADDRESS_ID",
        "ADDRESS_USAGE_TYPE_CODE",
        "REGION_CODE",
        "DISTRICT_CODE",
        "PROVINCE_STATE_ID",
        "COUNTRY_ID",
        "STREET_ADDRESS_1",
        "STREET_ADDRESS_2",
        "STREET_ADDRESS_3",
        "MUNICIPALITY_NAME",
        "POSTAL_CODE",
        "LATITUDE",
        "LONGITUDE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "ADDRESS_ID",
        "ADDRESS_USAGE_TYPE_CODE",
        "REGION_CODE",
        "DISTRICT_CODE",
        "PROVINCE_STATE_ID",
        "COUNTRY_ID",
        "STREET_ADDRESS_1",
        "STREET_ADDRESS_2",
        "STREET_ADDRESS_3",
        "MUNICIPALITY_NAME",
        "POSTAL_CODE",
        "LATITUDE",
        "LONGITUDE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_LEASE_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_LEASE_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_LEASE_I_S_U_TR] ON PIMS_LEASE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.LEASE_ID = deleted.LEASE_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_LEASE
      set "LEASE_ID" = inserted."LEASE_ID",
        "MOTI_NAME_ID" = inserted."MOTI_NAME_ID",
        "LEASE_PAY_RVBL_TYPE_CODE" = inserted."LEASE_PAY_RVBL_TYPE_CODE",
        "LEASE_LICENSE_TYPE_CODE" = inserted."LEASE_LICENSE_TYPE_CODE",
        "LEASE_CATEGORY_TYPE_CODE" = inserted."LEASE_CATEGORY_TYPE_CODE",
        "LEASE_PURPOSE_TYPE_CODE" = inserted."LEASE_PURPOSE_TYPE_CODE",
        "LEASE_PROGRAM_TYPE_CODE" = inserted."LEASE_PROGRAM_TYPE_CODE",
        "LEASE_PMT_FREQ_TYPE_CODE" = inserted."LEASE_PMT_FREQ_TYPE_CODE",
        "LEASE_PURPOSE_OTHER_DESC" = inserted."LEASE_PURPOSE_OTHER_DESC",
        "L_FILE_NO" = inserted."L_FILE_NO",
        "TFA_FILE_NO" = inserted."TFA_FILE_NO",
        "PS_FILE_NO" = inserted."PS_FILE_NO",
        "LEASE_DESCRIPTION" = inserted."LEASE_DESCRIPTION",
        "LEASE_NOTES" = inserted."LEASE_NOTES",
        "ORIG_START_DATE" = inserted."ORIG_START_DATE",
        "ORIG_EXPIRY_DATE" = inserted."ORIG_EXPIRY_DATE",
        "IS_ORIG_EXPIRY_REQUIRED" = inserted."IS_ORIG_EXPIRY_REQUIRED",
        "TERM_START_DATE" = inserted."TERM_START_DATE",
        "TERM_EXPIRY_DATE" = inserted."TERM_EXPIRY_DATE",
        "TERM_RENEWAL_DATE" = inserted."TERM_RENEWAL_DATE",
        "INCLUDED_RENEWALS" = inserted."INCLUDED_RENEWALS",
        "RENEWAL_COUNT" = inserted."RENEWAL_COUNT",
        "RENEWAL_TERM_MONTHS" = inserted."RENEWAL_TERM_MONTHS",
        "LEASE_AMOUNT" = inserted."LEASE_AMOUNT",
        "INSPECTION_DATE" = inserted."INSPECTION_DATE",
        "INSPECTION_NOTES" = inserted."INSPECTION_NOTES",
        "IS_EXPIRED" = inserted."IS_EXPIRED",
        "HAS_PHYSICAL_FILE" = inserted."HAS_PHYSICAL_FILE",
        "HAS_DIGITAL_FILE" = inserted."HAS_DIGITAL_FILE",
        "HAS_PHYSICIAL_LICENSE" = inserted."HAS_PHYSICIAL_LICENSE",
        "HAS_DIGITAL_LICENSE" = inserted."HAS_DIGITAL_LICENSE",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_LEASE
      inner join inserted
      on (PIMS_LEASE.LEASE_ID = inserted.LEASE_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPACT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PRPACT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPACT_I_S_I_TR] ON PIMS_PROPERTY_ACTIVITY INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROPERTY_ACTIVITY ("PROPERTY_ACTIVITY_ID",
        "ACTIVITY_ID",
        "PROPERTY_ID",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "PROPERTY_ACTIVITY_ID",
        "ACTIVITY_ID",
        "PROPERTY_ID",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_INSRNC_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_INSRNC_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_INSRNC_A_S_IUD_TR] ON PIMS_INSURANCE FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_INSURANCE_HIST set END_DATE_HIST = @curr_date where INSURANCE_ID in (select INSURANCE_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_INSURANCE_HIST ([INSURANCE_ID], [LEASE_ID], [INSURANCE_TYPE_CODE], [INSURER_ORG_ID], [INSURER_CONTACT_ID], [MOTI_RISK_MGMT_CONTACT_ID], [BCTFA_RISK_MGMT_CONTACT_ID], [INSURANCE_PAYEE_TYPE_CODE], [OTHER_INSURANCE_TYPE], [COVERAGE_DESCRIPTION], [COVERAGE_LIMIT], [INSURED_VALUE], [START_DATE], [EXPIRY_DATE], [RISK ASSESSMENT_COMPLETED_DATE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _INSURANCE_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [INSURANCE_ID], [LEASE_ID], [INSURANCE_TYPE_CODE], [INSURER_ORG_ID], [INSURER_CONTACT_ID], [MOTI_RISK_MGMT_CONTACT_ID], [BCTFA_RISK_MGMT_CONTACT_ID], [INSURANCE_PAYEE_TYPE_CODE], [OTHER_INSURANCE_TYPE], [COVERAGE_DESCRIPTION], [COVERAGE_LIMIT], [INSURED_VALUE], [START_DATE], [EXPIRY_DATE], [RISK ASSESSMENT_COMPLETED_DATE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_INSURANCE_H_ID_SEQ]) as [_INSURANCE_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PROJCT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PROJCT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PROJCT_I_S_I_TR] ON PIMS_PROJECT INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROJECT ("PROJECT_ID",
        "PROJECT_TYPE_CODE",
        "PROJECT_STATUS_TYPE_CODE",
        "PROJECT_RISK_TYPE_CODE",
        "PROJECT_TIER_TYPE_CODE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "PROJECT_ID",
        "PROJECT_TYPE_CODE",
        "PROJECT_STATUS_TYPE_CODE",
        "PROJECT_RISK_TYPE_CODE",
        "PROJECT_TIER_TYPE_CODE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_USER_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_USER_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_USER_I_S_U_TR] ON PIMS_USER INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.USER_ID = deleted.USER_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_USER
      set "USER_ID" = inserted."USER_ID",
        "PERSON_ID" = inserted."PERSON_ID",
        "BUSINESS_IDENTIFIER_VALUE" = inserted."BUSINESS_IDENTIFIER_VALUE",
        "GUID_IDENTIFIER_VALUE" = inserted."GUID_IDENTIFIER_VALUE",
        "POSITION" = inserted."POSITION",
        "NOTE" = inserted."NOTE",
        "LAST_LOGIN" = inserted."LAST_LOGIN",
        "APPROVED_BY_ID" = inserted."APPROVED_BY_ID",
        "ISSUE_DATE" = inserted."ISSUE_DATE",
        "EXPIRY_DATE" = inserted."EXPIRY_DATE",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_USER
      inner join inserted
      on (PIMS_USER.USER_ID = inserted.USER_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRJRSK_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PRJRSK_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRJRSK_I_S_U_TR] ON PIMS_PROJECT_RISK_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROJECT_RISK_TYPE_CODE = deleted.PROJECT_RISK_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROJECT_RISK_TYPE
      set "PROJECT_RISK_TYPE_CODE" = inserted."PROJECT_RISK_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROJECT_RISK_TYPE
      inner join inserted
      on (PIMS_PROJECT_RISK_TYPE.PROJECT_RISK_TYPE_CODE = inserted.PROJECT_RISK_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_LSPRTY_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_LSPRTY_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_LSPRTY_I_S_U_TR] ON PIMS_LEASE_PAY_RVBL_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.LEASE_PAY_RVBL_TYPE_CODE = deleted.LEASE_PAY_RVBL_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_LEASE_PAY_RVBL_TYPE
      set "LEASE_PAY_RVBL_TYPE_CODE" = inserted."LEASE_PAY_RVBL_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_LEASE_PAY_RVBL_TYPE
      inner join inserted
      on (PIMS_LEASE_PAY_RVBL_TYPE.LEASE_PAY_RVBL_TYPE_CODE = inserted.LEASE_PAY_RVBL_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_SDRTRN_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_SDRTRN_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_SDRTRN_I_S_U_TR] ON PIMS_SECURITY_DEPOSIT_RETURN INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.SECURITY_DEPOSIT_RETURN_ID = deleted.SECURITY_DEPOSIT_RETURN_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_SECURITY_DEPOSIT_RETURN
      set "SECURITY_DEPOSIT_RETURN_ID" = inserted."SECURITY_DEPOSIT_RETURN_ID",
        "LEASE_ID" = inserted."LEASE_ID",
        "SECURITY_DEPOSIT_TYPE_CODE" = inserted."SECURITY_DEPOSIT_TYPE_CODE",
        "TERMINATION_DATE" = inserted."TERMINATION_DATE",
        "DEPOSIT_TOTAL" = inserted."DEPOSIT_TOTAL",
        "CLAIMS_AGAINST" = inserted."CLAIMS_AGAINST",
        "RETURN_AMOUNT" = inserted."RETURN_AMOUNT",
        "RETURN_DATE" = inserted."RETURN_DATE",
        "CHEQUE_NUMBER" = inserted."CHEQUE_NUMBER",
        "PAYEE_NAME" = inserted."PAYEE_NAME",
        "PAYEE_ADDRESS" = inserted."PAYEE_ADDRESS",
        "TERMINATION_NOTE" = inserted."TERMINATION_NOTE",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_SECURITY_DEPOSIT_RETURN
      inner join inserted
      on (PIMS_SECURITY_DEPOSIT_RETURN.SECURITY_DEPOSIT_RETURN_ID = inserted.SECURITY_DEPOSIT_RETURN_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PIMPRT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PIMPRT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PIMPRT_I_S_I_TR] ON PIMS_PROPERTY_IMPROVEMENT_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROPERTY_IMPROVEMENT_TYPE ("PROPERTY_IMPROVEMENT_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "PROPERTY_IMPROVEMENT_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPEVL_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PRPEVL_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPEVL_I_S_I_TR] ON PIMS_PROPERTY_EVALUATION INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROPERTY_EVALUATION ("PROPERTY_EVALUATION_ID",
        "PROPERTY_ID",
        "EVALUATION_DATE",
        "KEY",
        "VALUE",
        "NOTE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "PROPERTY_EVALUATION_ID",
        "PROPERTY_ID",
        "EVALUATION_DATE",
        "KEY",
        "VALUE",
        "NOTE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_INSPYT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_INSPYT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_INSPYT_I_S_I_TR] ON PIMS_INSURANCE_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_INSURANCE_TYPE ("INSURANCE_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "INSURANCE_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ARQSTT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_ARQSTT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ARQSTT_I_S_I_TR] ON PIMS_ACCESS_REQUEST_STATUS_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_ACCESS_REQUEST_STATUS_TYPE ("ACCESS_REQUEST_STATUS_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "ACCESS_REQUEST_STATUS_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ROLE_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_ROLE_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ROLE_I_S_U_TR] ON PIMS_ROLE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.ROLE_ID = deleted.ROLE_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_ROLE
      set "ROLE_ID" = inserted."ROLE_ID",
        "ROLE_UID" = inserted."ROLE_UID",
        "KEYCLOAK_GROUP_ID" = inserted."KEYCLOAK_GROUP_ID",
        "NAME" = inserted."NAME",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_PUBLIC" = inserted."IS_PUBLIC",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "SORT_ORDER" = inserted."SORT_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_ROLE
      inner join inserted
      on (PIMS_ROLE.ROLE_ID = inserted.ROLE_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPSVC_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PRPSVC_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPSVC_I_S_I_TR] ON PIMS_PROPERTY_SERVICE_FILE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROPERTY_SERVICE_FILE ("PROPERTY_SERVICE_FILE_ID",
        "PROPERTY_SERVICE_FILE_TYPE_CODE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "PROPERTY_SERVICE_FILE_ID",
        "PROPERTY_SERVICE_FILE_TYPE_CODE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PIDSRT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PIDSRT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PIDSRT_I_S_I_TR] ON PIMS_PROPERTY_DATA_SOURCE_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROPERTY_DATA_SOURCE_TYPE ("PROPERTY_DATA_SOURCE_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "PROPERTY_DATA_SOURCE_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPACT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PRPACT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPACT_I_S_U_TR] ON PIMS_PROPERTY_ACTIVITY INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROPERTY_ACTIVITY_ID = deleted.PROPERTY_ACTIVITY_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROPERTY_ACTIVITY
      set "PROPERTY_ACTIVITY_ID" = inserted."PROPERTY_ACTIVITY_ID",
        "ACTIVITY_ID" = inserted."ACTIVITY_ID",
        "PROPERTY_ID" = inserted."PROPERTY_ID",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROPERTY_ACTIVITY
      inner join inserted
      on (PIMS_PROPERTY_ACTIVITY.PROPERTY_ACTIVITY_ID = inserted.PROPERTY_ACTIVITY_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_INSPAY_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_INSPAY_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_INSPAY_I_S_U_TR] ON PIMS_INSURANCE_PAYEE_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.INSURANCE_PAYEE_TYPE_CODE = deleted.INSURANCE_PAYEE_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_INSURANCE_PAYEE_TYPE
      set "INSURANCE_PAYEE_TYPE_CODE" = inserted."INSURANCE_PAYEE_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_INSURANCE_PAYEE_TYPE
      inner join inserted
      on (PIMS_INSURANCE_PAYEE_TYPE.INSURANCE_PAYEE_TYPE_CODE = inserted.INSURANCE_PAYEE_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PERORG_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PERORG_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PERORG_I_S_U_TR] ON PIMS_PERSON_ORGANIZATION INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PERSON_ORGANIZATION_ID = deleted.PERSON_ORGANIZATION_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PERSON_ORGANIZATION
      set "PERSON_ORGANIZATION_ID" = inserted."PERSON_ORGANIZATION_ID",
        "PERSON_ID" = inserted."PERSON_ID",
        "ORGANIZATION_ID" = inserted."ORGANIZATION_ID",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PERSON_ORGANIZATION
      inner join inserted
      on (PIMS_PERSON_ORGANIZATION.PERSON_ORGANIZATION_ID = inserted.PERSON_ORGANIZATION_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_TSKTAM_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_TSKTAM_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_TSKTAM_I_S_U_TR] ON PIMS_TASK_TEMPLATE_ACTIVITY_MODEL INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.TASK_TEMPLATE_ACTIVITY_MODEL_ID = deleted.TASK_TEMPLATE_ACTIVITY_MODEL_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_TASK_TEMPLATE_ACTIVITY_MODEL
      set "TASK_TEMPLATE_ACTIVITY_MODEL_ID" = inserted."TASK_TEMPLATE_ACTIVITY_MODEL_ID",
        "TASK_TEMPLATE_ID" = inserted."TASK_TEMPLATE_ID",
        "ACTIVITY_MODEL_ID" = inserted."ACTIVITY_MODEL_ID",
        "IS_MANDATORY" = inserted."IS_MANDATORY",
        "IMPLEMENTATION_ORDER" = inserted."IMPLEMENTATION_ORDER",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_TASK_TEMPLATE_ACTIVITY_MODEL
      inner join inserted
      on (PIMS_TASK_TEMPLATE_ACTIVITY_MODEL.TASK_TEMPLATE_ACTIVITY_MODEL_ID = inserted.TASK_TEMPLATE_ACTIVITY_MODEL_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_USRORG_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_USRORG_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_USRORG_A_S_IUD_TR] ON PIMS_USER_ORGANIZATION FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_USER_ORGANIZATION_HIST set END_DATE_HIST = @curr_date where USER_ORGANIZATION_ID in (select USER_ORGANIZATION_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_USER_ORGANIZATION_HIST ([USER_ORGANIZATION_ID], [ORGANIZATION_ID], [USER_ID], [ROLE_ID], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _USER_ORGANIZATION_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [USER_ORGANIZATION_ID], [ORGANIZATION_ID], [USER_ID], [ROLE_ID], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_USER_ORGANIZATION_H_ID_SEQ]) as [_USER_ORGANIZATION_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_LSPRGT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_LSPRGT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_LSPRGT_I_S_U_TR] ON PIMS_LEASE_PROGRAM_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.LEASE_PROGRAM_TYPE_CODE = deleted.LEASE_PROGRAM_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_LEASE_PROGRAM_TYPE
      set "LEASE_PROGRAM_TYPE_CODE" = inserted."LEASE_PROGRAM_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_LEASE_PROGRAM_TYPE
      inner join inserted
      on (PIMS_LEASE_PROGRAM_TYPE.LEASE_PROGRAM_TYPE_CODE = inserted.LEASE_PROGRAM_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPORG_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PRPORG_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPORG_I_S_I_TR] ON PIMS_PROPERTY_ORGANIZATION INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROPERTY_ORGANIZATION ("PROPERTY_ORGANIZATION_ID",
        "PROPERTY_ID",
        "ORGANIZATION_ID",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY",
        "IS_DISABLED")
      select "PROPERTY_ORGANIZATION_ID",
        "PROPERTY_ID",
        "ORGANIZATION_ID",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY",
        "IS_DISABLED"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_LSPMTF_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_LSPMTF_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_LSPMTF_I_S_U_TR] ON PIMS_LEASE_PMT_FREQ_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.LEASE_PMT_FREQ_TYPE_CODE = deleted.LEASE_PMT_FREQ_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_LEASE_PMT_FREQ_TYPE
      set "LEASE_PMT_FREQ_TYPE_CODE" = inserted."LEASE_PMT_FREQ_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_LEASE_PMT_FREQ_TYPE
      inner join inserted
      on (PIMS_LEASE_PMT_FREQ_TYPE.LEASE_PMT_FREQ_TYPE_CODE = inserted.LEASE_PMT_FREQ_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRJSTY_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PRJSTY_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRJSTY_I_S_U_TR] ON PIMS_PROJECT_STATUS_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROJECT_STATUS_TYPE_CODE = deleted.PROJECT_STATUS_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROJECT_STATUS_TYPE
      set "PROJECT_STATUS_TYPE_CODE" = inserted."PROJECT_STATUS_TYPE_CODE",
        "CODE_GROUP" = inserted."CODE_GROUP",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "TEXT" = inserted."TEXT",
        "IS_MILESTONE" = inserted."IS_MILESTONE",
        "IS_TERMINAL" = inserted."IS_TERMINAL",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROJECT_STATUS_TYPE
      inner join inserted
      on (PIMS_PROJECT_STATUS_TYPE.PROJECT_STATUS_TYPE_CODE = inserted.PROJECT_STATUS_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ACTMDL_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_ACTMDL_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ACTMDL_A_S_IUD_TR] ON PIMS_ACTIVITY_MODEL FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_ACTIVITY_MODEL_HIST set END_DATE_HIST = @curr_date where ACTIVITY_MODEL_ID in (select ACTIVITY_MODEL_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_ACTIVITY_MODEL_HIST ([ACTIVITY_MODEL_ID], [DESCRIPTION], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _ACTIVITY_MODEL_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [ACTIVITY_MODEL_ID], [DESCRIPTION], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_ACTIVITY_MODEL_H_ID_SEQ]) as [_ACTIVITY_MODEL_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPRTY_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PRPRTY_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPRTY_I_S_U_TR] ON PIMS_PROPERTY INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROPERTY_ID = deleted.PROPERTY_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROPERTY
      set "PROPERTY_ID" = inserted."PROPERTY_ID",
        "PROPERTY_MANAGER_ID" = inserted."PROPERTY_MANAGER_ID",
        "PROP_MGMT_ORG_ID" = inserted."PROP_MGMT_ORG_ID",
        "PROPERTY_TYPE_CODE" = inserted."PROPERTY_TYPE_CODE",
        "PROPERTY_CLASSIFICATION_TYPE_CODE" = inserted."PROPERTY_CLASSIFICATION_TYPE_CODE",
        "ADDRESS_ID" = inserted."ADDRESS_ID",
        "REGION_CODE" = inserted."REGION_CODE",
        "DISTRICT_CODE" = inserted."DISTRICT_CODE",
        "PROPERTY_TENURE_TYPE_CODE" = inserted."PROPERTY_TENURE_TYPE_CODE",
        "PROPERTY_AREA_UNIT_TYPE_CODE" = inserted."PROPERTY_AREA_UNIT_TYPE_CODE",
        "PROPERTY_STATUS_TYPE_CODE" = inserted."PROPERTY_STATUS_TYPE_CODE",
        "SURPLUS_DECLARATION_TYPE_CODE" = inserted."SURPLUS_DECLARATION_TYPE_CODE",
        "PROPERTY_DATA_SOURCE_TYPE_CODE" = inserted."PROPERTY_DATA_SOURCE_TYPE_CODE",
        "PROPERTY_DATA_SOURCE_EFFECTIVE_DATE" = inserted."PROPERTY_DATA_SOURCE_EFFECTIVE_DATE",
        "NAME" = inserted."NAME",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "PID" = inserted."PID",
        "PIN" = inserted."PIN",
        "LAND_AREA" = inserted."LAND_AREA",
        "LAND_LEGAL_DESCRIPTION" = inserted."LAND_LEGAL_DESCRIPTION",
        "BOUNDARY" = inserted."BOUNDARY",
        "LOCATION" = inserted."LOCATION",
        "ENCUMBRANCE_REASON" = inserted."ENCUMBRANCE_REASON",
        "SURPLUS_DECLARATION_COMMENT" = inserted."SURPLUS_DECLARATION_COMMENT",
        "SURPLUS_DECLARATION_DATE" = inserted."SURPLUS_DECLARATION_DATE",
        "IS_OWNED" = inserted."IS_OWNED",
        "IS_PROPERTY_OF_INTEREST" = inserted."IS_PROPERTY_OF_INTEREST",
        "IS_VISIBLE_TO_OTHER_AGENCIES" = inserted."IS_VISIBLE_TO_OTHER_AGENCIES",
        "IS_SENSITIVE" = inserted."IS_SENSITIVE",
        "ZONING" = inserted."ZONING",
        "ZONING_POTENTIAL" = inserted."ZONING_POTENTIAL",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROPERTY
      inner join inserted
      on (PIMS_PROPERTY.PROPERTY_ID = inserted.PROPERTY_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PERSON_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PERSON_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PERSON_I_S_I_TR] ON PIMS_PERSON INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PERSON ("PERSON_ID",
        "ADDRESS_ID",
        "SURNAME",
        "FIRST_NAME",
        "MIDDLE_NAMES",
        "NAME_SUFFIX",
        "BIRTH_DATE",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "PERSON_ID",
        "ADDRESS_ID",
        "SURNAME",
        "FIRST_NAME",
        "MIDDLE_NAMES",
        "NAME_SUFFIX",
        "BIRTH_DATE",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRWKMD_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PRWKMD_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRWKMD_I_S_U_TR] ON PIMS_PROJECT_WORKFLOW_MODEL INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROJECT_WORKFLOW_MODEL_ID = deleted.PROJECT_WORKFLOW_MODEL_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROJECT_WORKFLOW_MODEL
      set "PROJECT_WORKFLOW_MODEL_ID" = inserted."PROJECT_WORKFLOW_MODEL_ID",
        "PROJECT_ID" = inserted."PROJECT_ID",
        "WORKFLOW_MODEL_ID" = inserted."WORKFLOW_MODEL_ID",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROJECT_WORKFLOW_MODEL
      inner join inserted
      on (PIMS_PROJECT_WORKFLOW_MODEL.PROJECT_WORKFLOW_MODEL_ID = inserted.PROJECT_WORKFLOW_MODEL_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PIDSRT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PIDSRT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PIDSRT_I_S_U_TR] ON PIMS_PROPERTY_DATA_SOURCE_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROPERTY_DATA_SOURCE_TYPE_CODE = deleted.PROPERTY_DATA_SOURCE_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROPERTY_DATA_SOURCE_TYPE
      set "PROPERTY_DATA_SOURCE_TYPE_CODE" = inserted."PROPERTY_DATA_SOURCE_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROPERTY_DATA_SOURCE_TYPE
      inner join inserted
      on (PIMS_PROPERTY_DATA_SOURCE_TYPE.PROPERTY_DATA_SOURCE_TYPE_CODE = inserted.PROPERTY_DATA_SOURCE_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPRTY_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PRPRTY_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPRTY_I_S_I_TR] ON PIMS_PROPERTY INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROPERTY ("PROPERTY_ID",
        "PROPERTY_MANAGER_ID",
        "PROP_MGMT_ORG_ID",
        "PROPERTY_TYPE_CODE",
        "PROPERTY_CLASSIFICATION_TYPE_CODE",
        "ADDRESS_ID",
        "REGION_CODE",
        "DISTRICT_CODE",
        "PROPERTY_TENURE_TYPE_CODE",
        "PROPERTY_AREA_UNIT_TYPE_CODE",
        "PROPERTY_STATUS_TYPE_CODE",
        "SURPLUS_DECLARATION_TYPE_CODE",
        "PROPERTY_DATA_SOURCE_TYPE_CODE",
        "PROPERTY_DATA_SOURCE_EFFECTIVE_DATE",
        "NAME",
        "DESCRIPTION",
        "PID",
        "PIN",
        "LAND_AREA",
        "LAND_LEGAL_DESCRIPTION",
        "BOUNDARY",
        "LOCATION",
        "ENCUMBRANCE_REASON",
        "SURPLUS_DECLARATION_COMMENT",
        "SURPLUS_DECLARATION_DATE",
        "IS_OWNED",
        "IS_PROPERTY_OF_INTEREST",
        "IS_VISIBLE_TO_OTHER_AGENCIES",
        "IS_SENSITIVE",
        "ZONING",
        "ZONING_POTENTIAL",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "PROPERTY_ID",
        "PROPERTY_MANAGER_ID",
        "PROP_MGMT_ORG_ID",
        "PROPERTY_TYPE_CODE",
        "PROPERTY_CLASSIFICATION_TYPE_CODE",
        "ADDRESS_ID",
        "REGION_CODE",
        "DISTRICT_CODE",
        "PROPERTY_TENURE_TYPE_CODE",
        "PROPERTY_AREA_UNIT_TYPE_CODE",
        "PROPERTY_STATUS_TYPE_CODE",
        "SURPLUS_DECLARATION_TYPE_CODE",
        "PROPERTY_DATA_SOURCE_TYPE_CODE",
        "PROPERTY_DATA_SOURCE_EFFECTIVE_DATE",
        "NAME",
        "DESCRIPTION",
        "PID",
        "PIN",
        "LAND_AREA",
        "LAND_LEGAL_DESCRIPTION",
        "BOUNDARY",
        "LOCATION",
        "ENCUMBRANCE_REASON",
        "SURPLUS_DECLARATION_COMMENT",
        "SURPLUS_DECLARATION_DATE",
        "IS_OWNED",
        "IS_PROPERTY_OF_INTEREST",
        "IS_VISIBLE_TO_OTHER_AGENCIES",
        "IS_SENSITIVE",
        "ZONING",
        "ZONING_POTENTIAL",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_LPRPTY_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_LPRPTY_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_LPRPTY_I_S_U_TR] ON PIMS_LEASE_PURPOSE_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.LEASE_PURPOSE_TYPE_CODE = deleted.LEASE_PURPOSE_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_LEASE_PURPOSE_TYPE
      set "LEASE_PURPOSE_TYPE_CODE" = inserted."LEASE_PURPOSE_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_LEASE_PURPOSE_TYPE
      inner join inserted
      on (PIMS_LEASE_PURPOSE_TYPE.LEASE_PURPOSE_TYPE_CODE = inserted.LEASE_PURPOSE_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_SECDEP_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_SECDEP_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_SECDEP_I_S_U_TR] ON PIMS_SECURITY_DEPOSIT INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.SECURITY_DEPOSIT_ID = deleted.SECURITY_DEPOSIT_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_SECURITY_DEPOSIT
      set "SECURITY_DEPOSIT_ID" = inserted."SECURITY_DEPOSIT_ID",
        "LEASE_ID" = inserted."LEASE_ID",
        "SEC_DEP_HOLDER_TYPE_CODE" = inserted."SEC_DEP_HOLDER_TYPE_CODE",
        "SECURITY_DEPOSIT_TYPE_CODE" = inserted."SECURITY_DEPOSIT_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "AMOUNT_PAID" = inserted."AMOUNT_PAID",
        "TOTAL_AMOUNT" = inserted."TOTAL_AMOUNT",
        "DEPOSIT_DATE" = inserted."DEPOSIT_DATE",
        "ANNUAL_INTEREST_RATE" = inserted."ANNUAL_INTEREST_RATE",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_SECURITY_DEPOSIT
      inner join inserted
      on (PIMS_SECURITY_DEPOSIT.SECURITY_DEPOSIT_ID = inserted.SECURITY_DEPOSIT_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPORG_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_PRPORG_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPORG_A_S_IUD_TR] ON PIMS_PROPERTY_ORGANIZATION FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_PROPERTY_ORGANIZATION_HIST set END_DATE_HIST = @curr_date where PROPERTY_ORGANIZATION_ID in (select PROPERTY_ORGANIZATION_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_PROPERTY_ORGANIZATION_HIST ([PROPERTY_ORGANIZATION_ID], [PROPERTY_ID], [ORGANIZATION_ID], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [IS_DISABLED], _PROPERTY_ORGANIZATION_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [PROPERTY_ORGANIZATION_ID], [PROPERTY_ID], [ORGANIZATION_ID], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [IS_DISABLED], (next value for [dbo].[PIMS_PROPERTY_ORGANIZATION_H_ID_SEQ]) as [_PROPERTY_ORGANIZATION_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_TSKTMT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_TSKTMT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_TSKTMT_I_S_U_TR] ON PIMS_TASK_TEMPLATE_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.TASK_TEMPLATE_TYPE_CODE = deleted.TASK_TEMPLATE_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_TASK_TEMPLATE_TYPE
      set "TASK_TEMPLATE_TYPE_CODE" = inserted."TASK_TEMPLATE_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_TASK_TEMPLATE_TYPE
      inner join inserted
      on (PIMS_TASK_TEMPLATE_TYPE.TASK_TEMPLATE_TYPE_CODE = inserted.TASK_TEMPLATE_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ORGIDT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_ORGIDT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ORGIDT_I_S_I_TR] ON PIMS_ORG_IDENTIFIER_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_ORG_IDENTIFIER_TYPE ("ORG_IDENTIFIER_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "ORG_IDENTIFIER_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ACRQOR_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_ACRQOR_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ACRQOR_A_S_IUD_TR] ON PIMS_ACCESS_REQUEST_ORGANIZATION FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_ACCESS_REQUEST_ORGANIZATION_HIST set END_DATE_HIST = @curr_date where ACCESS_REQUEST_ORGANIZATION_ID in (select ACCESS_REQUEST_ORGANIZATION_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_ACCESS_REQUEST_ORGANIZATION_HIST ([ACCESS_REQUEST_ORGANIZATION_ID], [ORGANIZATION_ID], [ACCESS_REQUEST_ID], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _ACCESS_REQUEST_ORGANIZATION_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [ACCESS_REQUEST_ORGANIZATION_ID], [ORGANIZATION_ID], [ACCESS_REQUEST_ID], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_ACCESS_REQUEST_ORGANIZATION_H_ID_SEQ]) as [_ACCESS_REQUEST_ORGANIZATION_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPCLT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PRPCLT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPCLT_I_S_I_TR] ON PIMS_PROPERTY_CLASSIFICATION_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROPERTY_CLASSIFICATION_TYPE ("PROPERTY_CLASSIFICATION_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "PROPERTY_CLASSIFICATION_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ACRQST_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_ACRQST_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ACRQST_I_S_U_TR] ON PIMS_ACCESS_REQUEST INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.ACCESS_REQUEST_ID = deleted.ACCESS_REQUEST_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_ACCESS_REQUEST
      set "ACCESS_REQUEST_ID" = inserted."ACCESS_REQUEST_ID",
        "USER_ID" = inserted."USER_ID",
        "ROLE_ID" = inserted."ROLE_ID",
        "ACCESS_REQUEST_STATUS_TYPE_CODE" = inserted."ACCESS_REQUEST_STATUS_TYPE_CODE",
        "NOTE" = inserted."NOTE",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_ACCESS_REQUEST
      inner join inserted
      on (PIMS_ACCESS_REQUEST.ACCESS_REQUEST_ID = inserted.ACCESS_REQUEST_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_LEASE_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_LEASE_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_LEASE_A_S_IUD_TR] ON PIMS_LEASE FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_LEASE_HIST set END_DATE_HIST = @curr_date where LEASE_ID in (select LEASE_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_LEASE_HIST ([LEASE_ID], [MOTI_NAME_ID], [LEASE_PAY_RVBL_TYPE_CODE], [LEASE_LICENSE_TYPE_CODE], [LEASE_CATEGORY_TYPE_CODE], [LEASE_PURPOSE_TYPE_CODE], [LEASE_PROGRAM_TYPE_CODE], [LEASE_PMT_FREQ_TYPE_CODE], [LEASE_PURPOSE_OTHER_DESC], [L_FILE_NO], [TFA_FILE_NO], [PS_FILE_NO], [LEASE_DESCRIPTION], [LEASE_NOTES], [ORIG_START_DATE], [ORIG_EXPIRY_DATE], [IS_ORIG_EXPIRY_REQUIRED], [TERM_START_DATE], [TERM_EXPIRY_DATE], [TERM_RENEWAL_DATE], [INCLUDED_RENEWALS], [RENEWAL_COUNT], [RENEWAL_TERM_MONTHS], [LEASE_AMOUNT], [INSPECTION_DATE], [INSPECTION_NOTES], [IS_EXPIRED], [HAS_PHYSICAL_FILE], [HAS_DIGITAL_FILE], [HAS_PHYSICIAL_LICENSE], [HAS_DIGITAL_LICENSE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _LEASE_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [LEASE_ID], [MOTI_NAME_ID], [LEASE_PAY_RVBL_TYPE_CODE], [LEASE_LICENSE_TYPE_CODE], [LEASE_CATEGORY_TYPE_CODE], [LEASE_PURPOSE_TYPE_CODE], [LEASE_PROGRAM_TYPE_CODE], [LEASE_PMT_FREQ_TYPE_CODE], [LEASE_PURPOSE_OTHER_DESC], [L_FILE_NO], [TFA_FILE_NO], [PS_FILE_NO], [LEASE_DESCRIPTION], [LEASE_NOTES], [ORIG_START_DATE], [ORIG_EXPIRY_DATE], [IS_ORIG_EXPIRY_REQUIRED], [TERM_START_DATE], [TERM_EXPIRY_DATE], [TERM_RENEWAL_DATE], [INCLUDED_RENEWALS], [RENEWAL_COUNT], [RENEWAL_TERM_MONTHS], [LEASE_AMOUNT], [INSPECTION_DATE], [INSPECTION_NOTES], [IS_EXPIRED], [HAS_PHYSICAL_FILE], [HAS_DIGITAL_FILE], [HAS_PHYSICIAL_LICENSE], [HAS_DIGITAL_LICENSE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_LEASE_H_ID_SEQ]) as [_LEASE_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PROJTR_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PROJTR_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PROJTR_I_S_I_TR] ON PIMS_PROJECT_TIER_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROJECT_TIER_TYPE ("PROJECT_TIER_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "PROJECT_TIER_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_LSPRGT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_LSPRGT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_LSPRGT_I_S_I_TR] ON PIMS_LEASE_PROGRAM_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_LEASE_PROGRAM_TYPE ("LEASE_PROGRAM_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "LEASE_PROGRAM_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ACTMDL_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_ACTMDL_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ACTMDL_I_S_I_TR] ON PIMS_ACTIVITY_MODEL INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_ACTIVITY_MODEL ("ACTIVITY_MODEL_ID",
        "DESCRIPTION",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "ACTIVITY_MODEL_ID",
        "DESCRIPTION",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPSTS_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PRPSTS_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPSTS_I_S_I_TR] ON PIMS_PROPERTY_STATUS_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROPERTY_STATUS_TYPE ("PROPERTY_STATUS_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "PROPERTY_STATUS_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_CNTMTH_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_CNTMTH_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_CNTMTH_I_S_U_TR] ON PIMS_CONTACT_METHOD INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.CONTACT_METHOD_ID = deleted.CONTACT_METHOD_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_CONTACT_METHOD
      set "CONTACT_METHOD_ID" = inserted."CONTACT_METHOD_ID",
        "CONTACT_METHOD_TYPE_CODE" = inserted."CONTACT_METHOD_TYPE_CODE",
        "PERSON_ID" = inserted."PERSON_ID",
        "ORGANIZATION_ID" = inserted."ORGANIZATION_ID",
        "CONTACT_METHOD_VALUE" = inserted."CONTACT_METHOD_VALUE",
        "IS_PREFERRED_METHOD" = inserted."IS_PREFERRED_METHOD",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_CONTACT_METHOD
      inner join inserted
      on (PIMS_CONTACT_METHOD.CONTACT_METHOD_ID = inserted.CONTACT_METHOD_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PIMPRV_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PIMPRV_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PIMPRV_I_S_I_TR] ON PIMS_PROPERTY_IMPROVEMENT INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROPERTY_IMPROVEMENT ("PROPERTY_IMPROVEMENT_ID",
        "PROPERTY_LEASE_ID",
        "PROPERTY_IMPROVEMENT_TYPE_CODE",
        "PROPERTY_IMPROVEMENT_UOM_TYPE_CODE",
        "IMPROVEMENT_DESCRIPTION",
        "STRUCTURE_SIZE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "PROPERTY_IMPROVEMENT_ID",
        "PROPERTY_LEASE_ID",
        "PROPERTY_IMPROVEMENT_TYPE_CODE",
        "PROPERTY_IMPROVEMENT_UOM_TYPE_CODE",
        "IMPROVEMENT_DESCRIPTION",
        "STRUCTURE_SIZE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPORG_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PRPORG_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPORG_I_S_U_TR] ON PIMS_PROPERTY_ORGANIZATION INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROPERTY_ORGANIZATION_ID = deleted.PROPERTY_ORGANIZATION_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROPERTY_ORGANIZATION
      set "PROPERTY_ORGANIZATION_ID" = inserted."PROPERTY_ORGANIZATION_ID",
        "PROPERTY_ID" = inserted."PROPERTY_ID",
        "ORGANIZATION_ID" = inserted."ORGANIZATION_ID",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY",
        "IS_DISABLED" = inserted."IS_DISABLED"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROPERTY_ORGANIZATION
      inner join inserted
      on (PIMS_PROPERTY_ORGANIZATION.PROPERTY_ORGANIZATION_ID = inserted.PROPERTY_ORGANIZATION_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ROLCLM_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_ROLCLM_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ROLCLM_A_S_IUD_TR] ON PIMS_ROLE_CLAIM FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_ROLE_CLAIM_HIST set END_DATE_HIST = @curr_date where ROLE_CLAIM_ID in (select ROLE_CLAIM_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_ROLE_CLAIM_HIST ([ROLE_CLAIM_ID], [ROLE_ID], [CLAIM_ID], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _ROLE_CLAIM_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [ROLE_CLAIM_ID], [ROLE_ID], [CLAIM_ID], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_ROLE_CLAIM_H_ID_SEQ]) as [_ROLE_CLAIM_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_WFLMDT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_WFLMDT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_WFLMDT_I_S_U_TR] ON PIMS_WORKFLOW_MODEL_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.WORKFLOW_MODEL_TYPE_CODE = deleted.WORKFLOW_MODEL_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_WORKFLOW_MODEL_TYPE
      set "WORKFLOW_MODEL_TYPE_CODE" = inserted."WORKFLOW_MODEL_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_WORKFLOW_MODEL_TYPE
      inner join inserted
      on (PIMS_WORKFLOW_MODEL_TYPE.WORKFLOW_MODEL_TYPE_CODE = inserted.WORKFLOW_MODEL_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ARUNIT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_ARUNIT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ARUNIT_I_S_I_TR] ON PIMS_AREA_UNIT_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_AREA_UNIT_TYPE ("AREA_UNIT_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "AREA_UNIT_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_SDRTRN_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_SDRTRN_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_SDRTRN_A_S_IUD_TR] ON PIMS_SECURITY_DEPOSIT_RETURN FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_SECURITY_DEPOSIT_RETURN_HIST set END_DATE_HIST = @curr_date where SECURITY_DEPOSIT_RETURN_ID in (select SECURITY_DEPOSIT_RETURN_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_SECURITY_DEPOSIT_RETURN_HIST ([SECURITY_DEPOSIT_RETURN_ID], [LEASE_ID], [SECURITY_DEPOSIT_TYPE_CODE], [TERMINATION_DATE], [DEPOSIT_TOTAL], [CLAIMS_AGAINST], [RETURN_AMOUNT], [RETURN_DATE], [CHEQUE_NUMBER], [PAYEE_NAME], [PAYEE_ADDRESS], [TERMINATION_NOTE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _SECURITY_DEPOSIT_RETURN_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [SECURITY_DEPOSIT_RETURN_ID], [LEASE_ID], [SECURITY_DEPOSIT_TYPE_CODE], [TERMINATION_DATE], [DEPOSIT_TOTAL], [CLAIMS_AGAINST], [RETURN_AMOUNT], [RETURN_DATE], [CHEQUE_NUMBER], [PAYEE_NAME], [PAYEE_ADDRESS], [TERMINATION_NOTE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_SECURITY_DEPOSIT_RETURN_H_ID_SEQ]) as [_SECURITY_DEPOSIT_RETURN_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PERSON_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PERSON_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PERSON_I_S_U_TR] ON PIMS_PERSON INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PERSON_ID = deleted.PERSON_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PERSON
      set "PERSON_ID" = inserted."PERSON_ID",
        "ADDRESS_ID" = inserted."ADDRESS_ID",
        "SURNAME" = inserted."SURNAME",
        "FIRST_NAME" = inserted."FIRST_NAME",
        "MIDDLE_NAMES" = inserted."MIDDLE_NAMES",
        "NAME_SUFFIX" = inserted."NAME_SUFFIX",
        "BIRTH_DATE" = inserted."BIRTH_DATE",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PERSON
      inner join inserted
      on (PIMS_PERSON.PERSON_ID = inserted.PERSON_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_TASK_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_TASK_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_TASK_I_S_U_TR] ON PIMS_TASK INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.TASK_ID = deleted.TASK_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_TASK
      set "TASK_ID" = inserted."TASK_ID",
        "TASK_TEMPLATE_ID" = inserted."TASK_TEMPLATE_ID",
        "ACTIVITY_ID" = inserted."ACTIVITY_ID",
        "USER_ID" = inserted."USER_ID",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_TASK
      inner join inserted
      on (PIMS_TASK.TASK_ID = inserted.TASK_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRWKMD_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PRWKMD_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRWKMD_I_S_I_TR] ON PIMS_PROJECT_WORKFLOW_MODEL INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROJECT_WORKFLOW_MODEL ("PROJECT_WORKFLOW_MODEL_ID",
        "PROJECT_ID",
        "WORKFLOW_MODEL_ID",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "PROJECT_WORKFLOW_MODEL_ID",
        "PROJECT_ID",
        "WORKFLOW_MODEL_ID",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRJPRP_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_PRJPRP_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRJPRP_A_S_IUD_TR] ON PIMS_PROJECT_PROPERTY FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_PROJECT_PROPERTY_HIST set END_DATE_HIST = @curr_date where PROJECT_PROPERTY_ID in (select PROJECT_PROPERTY_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_PROJECT_PROPERTY_HIST ([PROJECT_PROPERTY_ID], [PROJECT_ID], [PROPERTY_ID], [IS_DISABLED], [APP_CREATE_TIMESTAMP], [APP_CREATE_USER_DIRECTORY], [APP_CREATE_USER_GUID], [APP_CREATE_USERID], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USER_DIRECTORY], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USERID], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _PROJECT_PROPERTY_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [PROJECT_PROPERTY_ID], [PROJECT_ID], [PROPERTY_ID], [IS_DISABLED], [APP_CREATE_TIMESTAMP], [APP_CREATE_USER_DIRECTORY], [APP_CREATE_USER_GUID], [APP_CREATE_USERID], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USER_DIRECTORY], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USERID], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_PROJECT_PROPERTY_H_ID_SEQ]) as [_PROJECT_PROPERTY_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ACRQST_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_ACRQST_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ACRQST_I_S_I_TR] ON PIMS_ACCESS_REQUEST INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_ACCESS_REQUEST ("ACCESS_REQUEST_ID",
        "USER_ID",
        "ROLE_ID",
        "ACCESS_REQUEST_STATUS_TYPE_CODE",
        "NOTE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "ACCESS_REQUEST_ID",
        "USER_ID",
        "ROLE_ID",
        "ACCESS_REQUEST_STATUS_TYPE_CODE",
        "NOTE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_LPRPTY_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_LPRPTY_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_LPRPTY_I_S_I_TR] ON PIMS_LEASE_PURPOSE_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_LEASE_PURPOSE_TYPE ("LEASE_PURPOSE_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "LEASE_PURPOSE_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ROLCLM_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_ROLCLM_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ROLCLM_I_S_U_TR] ON PIMS_ROLE_CLAIM INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.ROLE_CLAIM_ID = deleted.ROLE_CLAIM_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_ROLE_CLAIM
      set "ROLE_CLAIM_ID" = inserted."ROLE_CLAIM_ID",
        "ROLE_ID" = inserted."ROLE_ID",
        "CLAIM_ID" = inserted."CLAIM_ID",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_ROLE_CLAIM
      inner join inserted
      on (PIMS_ROLE_CLAIM.ROLE_CLAIM_ID = inserted.ROLE_CLAIM_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_SCHLDT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_SCHLDT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_SCHLDT_I_S_I_TR] ON PIMS_SEC_DEP_HOLDER_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_SEC_DEP_HOLDER_TYPE ("SEC_DEP_HOLDER_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "SEC_DEP_HOLDER_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_TSKTMT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_TSKTMT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_TSKTMT_I_S_I_TR] ON PIMS_TASK_TEMPLATE_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_TASK_TEMPLATE_TYPE ("TASK_TEMPLATE_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "TASK_TEMPLATE_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PIMPRV_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PIMPRV_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PIMPRV_I_S_U_TR] ON PIMS_PROPERTY_IMPROVEMENT INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROPERTY_IMPROVEMENT_ID = deleted.PROPERTY_IMPROVEMENT_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROPERTY_IMPROVEMENT
      set "PROPERTY_IMPROVEMENT_ID" = inserted."PROPERTY_IMPROVEMENT_ID",
        "PROPERTY_LEASE_ID" = inserted."PROPERTY_LEASE_ID",
        "PROPERTY_IMPROVEMENT_TYPE_CODE" = inserted."PROPERTY_IMPROVEMENT_TYPE_CODE",
        "PROPERTY_IMPROVEMENT_UOM_TYPE_CODE" = inserted."PROPERTY_IMPROVEMENT_UOM_TYPE_CODE",
        "IMPROVEMENT_DESCRIPTION" = inserted."IMPROVEMENT_DESCRIPTION",
        "STRUCTURE_SIZE" = inserted."STRUCTURE_SIZE",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROPERTY_IMPROVEMENT
      inner join inserted
      on (PIMS_PROPERTY_IMPROVEMENT.PROPERTY_IMPROVEMENT_ID = inserted.PROPERTY_IMPROVEMENT_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPTYP_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PRPTYP_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPTYP_I_S_U_TR] ON PIMS_PROPERTY_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROPERTY_TYPE_CODE = deleted.PROPERTY_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROPERTY_TYPE
      set "PROPERTY_TYPE_CODE" = inserted."PROPERTY_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROPERTY_TYPE
      inner join inserted
      on (PIMS_PROPERTY_TYPE.PROPERTY_TYPE_CODE = inserted.PROPERTY_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_WFLMDT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_WFLMDT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_WFLMDT_I_S_I_TR] ON PIMS_WORKFLOW_MODEL_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_WORKFLOW_MODEL_TYPE ("WORKFLOW_MODEL_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "WORKFLOW_MODEL_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ORGIDT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_ORGIDT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ORGIDT_I_S_U_TR] ON PIMS_ORG_IDENTIFIER_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.ORG_IDENTIFIER_TYPE_CODE = deleted.ORG_IDENTIFIER_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_ORG_IDENTIFIER_TYPE
      set "ORG_IDENTIFIER_TYPE_CODE" = inserted."ORG_IDENTIFIER_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_ORG_IDENTIFIER_TYPE
      inner join inserted
      on (PIMS_ORG_IDENTIFIER_TYPE.ORG_IDENTIFIER_TYPE_CODE = inserted.ORG_IDENTIFIER_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRJPRP_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PRJPRP_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRJPRP_I_S_U_TR] ON PIMS_PROJECT_PROPERTY INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROJECT_PROPERTY_ID = deleted.PROJECT_PROPERTY_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROJECT_PROPERTY
      set "PROJECT_PROPERTY_ID" = inserted."PROJECT_PROPERTY_ID",
        "PROJECT_ID" = inserted."PROJECT_ID",
        "PROPERTY_ID" = inserted."PROPERTY_ID",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROJECT_PROPERTY
      inner join inserted
      on (PIMS_PROJECT_PROPERTY.PROJECT_PROPERTY_ID = inserted.PROJECT_PROPERTY_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPCLT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PRPCLT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPCLT_I_S_U_TR] ON PIMS_PROPERTY_CLASSIFICATION_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROPERTY_CLASSIFICATION_TYPE_CODE = deleted.PROPERTY_CLASSIFICATION_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROPERTY_CLASSIFICATION_TYPE
      set "PROPERTY_CLASSIFICATION_TYPE_CODE" = inserted."PROPERTY_CLASSIFICATION_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROPERTY_CLASSIFICATION_TYPE
      inner join inserted
      on (PIMS_PROPERTY_CLASSIFICATION_TYPE.PROPERTY_CLASSIFICATION_TYPE_CODE = inserted.PROPERTY_CLASSIFICATION_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ORGTYP_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_ORGTYP_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ORGTYP_I_S_U_TR] ON PIMS_ORGANIZATION_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.ORGANIZATION_TYPE_CODE = deleted.ORGANIZATION_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_ORGANIZATION_TYPE
      set "ORGANIZATION_TYPE_CODE" = inserted."ORGANIZATION_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_ORGANIZATION_TYPE
      inner join inserted
      on (PIMS_ORGANIZATION_TYPE.ORGANIZATION_TYPE_CODE = inserted.ORGANIZATION_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_SECDEP_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_SECDEP_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_SECDEP_A_S_IUD_TR] ON PIMS_SECURITY_DEPOSIT FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_SECURITY_DEPOSIT_HIST set END_DATE_HIST = @curr_date where SECURITY_DEPOSIT_ID in (select SECURITY_DEPOSIT_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_SECURITY_DEPOSIT_HIST ([SECURITY_DEPOSIT_ID], [LEASE_ID], [SEC_DEP_HOLDER_TYPE_CODE], [SECURITY_DEPOSIT_TYPE_CODE], [DESCRIPTION], [AMOUNT_PAID], [TOTAL_AMOUNT], [DEPOSIT_DATE], [ANNUAL_INTEREST_RATE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _SECURITY_DEPOSIT_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [SECURITY_DEPOSIT_ID], [LEASE_ID], [SEC_DEP_HOLDER_TYPE_CODE], [SECURITY_DEPOSIT_TYPE_CODE], [DESCRIPTION], [AMOUNT_PAID], [TOTAL_AMOUNT], [DEPOSIT_DATE], [ANNUAL_INTEREST_RATE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_SECURITY_DEPOSIT_H_ID_SEQ]) as [_SECURITY_DEPOSIT_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRJTYP_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PRJTYP_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRJTYP_I_S_I_TR] ON PIMS_PROJECT_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROJECT_TYPE ("PROJECT_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "PROJECT_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PROVNC_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PROVNC_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PROVNC_I_S_I_TR] ON PIMS_PROVINCE_STATE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROVINCE_STATE ("PROVINCE_STATE_ID",
        "COUNTRY_ID",
        "PROVINCE_STATE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "PROVINCE_STATE_ID",
        "COUNTRY_ID",
        "PROVINCE_STATE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_WFLMDL_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_WFLMDL_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_WFLMDL_I_S_U_TR] ON PIMS_WORKFLOW_MODEL INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.WORKFLOW_MODEL_ID = deleted.WORKFLOW_MODEL_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_WORKFLOW_MODEL
      set "WORKFLOW_MODEL_ID" = inserted."WORKFLOW_MODEL_ID",
        "WORKFLOW_MODEL_TYPE_CODE" = inserted."WORKFLOW_MODEL_TYPE_CODE",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_WORKFLOW_MODEL
      inner join inserted
      on (PIMS_WORKFLOW_MODEL.WORKFLOW_MODEL_ID = inserted.WORKFLOW_MODEL_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PROPLS_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PROPLS_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PROPLS_I_S_U_TR] ON PIMS_PROPERTY_LEASE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROPERTY_LEASE_ID = deleted.PROPERTY_LEASE_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROPERTY_LEASE
      set "PROPERTY_LEASE_ID" = inserted."PROPERTY_LEASE_ID",
        "PROPERTY_ID" = inserted."PROPERTY_ID",
        "LEASE_ID" = inserted."LEASE_ID",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROPERTY_LEASE
      inner join inserted
      on (PIMS_PROPERTY_LEASE.PROPERTY_LEASE_ID = inserted.PROPERTY_LEASE_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ACRQOR_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_ACRQOR_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ACRQOR_I_S_U_TR] ON PIMS_ACCESS_REQUEST_ORGANIZATION INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.ACCESS_REQUEST_ORGANIZATION_ID = deleted.ACCESS_REQUEST_ORGANIZATION_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_ACCESS_REQUEST_ORGANIZATION
      set "ACCESS_REQUEST_ORGANIZATION_ID" = inserted."ACCESS_REQUEST_ORGANIZATION_ID",
        "ORGANIZATION_ID" = inserted."ORGANIZATION_ID",
        "ACCESS_REQUEST_ID" = inserted."ACCESS_REQUEST_ID",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_ACCESS_REQUEST_ORGANIZATION
      inner join inserted
      on (PIMS_ACCESS_REQUEST_ORGANIZATION.ACCESS_REQUEST_ORGANIZATION_ID = inserted.ACCESS_REQUEST_ORGANIZATION_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_CNTMTH_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_CNTMTH_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_CNTMTH_I_S_I_TR] ON PIMS_CONTACT_METHOD INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_CONTACT_METHOD ("CONTACT_METHOD_ID",
        "CONTACT_METHOD_TYPE_CODE",
        "PERSON_ID",
        "ORGANIZATION_ID",
        "CONTACT_METHOD_VALUE",
        "IS_PREFERRED_METHOD",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "CONTACT_METHOD_ID",
        "CONTACT_METHOD_TYPE_CODE",
        "PERSON_ID",
        "ORGANIZATION_ID",
        "CONTACT_METHOD_VALUE",
        "IS_PREFERRED_METHOD",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_TENANT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_TENANT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_TENANT_I_S_U_TR] ON PIMS_LEASE_TENANT INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.LEASE_TENANT_ID = deleted.LEASE_TENANT_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_LEASE_TENANT
      set "LEASE_TENANT_ID" = inserted."LEASE_TENANT_ID",
        "LEASE_ID" = inserted."LEASE_ID",
        "PERSON_ID" = inserted."PERSON_ID",
        "ORGANIZATION_ID" = inserted."ORGANIZATION_ID",
        "LESSOR_TYPE_CODE" = inserted."LESSOR_TYPE_CODE",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_LEASE_TENANT
      inner join inserted
      on (PIMS_LEASE_TENANT.LEASE_TENANT_ID = inserted.LEASE_TENANT_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ACTMDL_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_ACTMDL_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ACTMDL_I_S_U_TR] ON PIMS_ACTIVITY_MODEL INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.ACTIVITY_MODEL_ID = deleted.ACTIVITY_MODEL_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_ACTIVITY_MODEL
      set "ACTIVITY_MODEL_ID" = inserted."ACTIVITY_MODEL_ID",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_ACTIVITY_MODEL
      inner join inserted
      on (PIMS_ACTIVITY_MODEL.ACTIVITY_MODEL_ID = inserted.ACTIVITY_MODEL_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PERORG_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_PERORG_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PERORG_A_S_IUD_TR] ON PIMS_PERSON_ORGANIZATION FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_PERSON_ORGANIZATION_HIST set END_DATE_HIST = @curr_date where PERSON_ORGANIZATION_ID in (select PERSON_ORGANIZATION_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_PERSON_ORGANIZATION_HIST ([PERSON_ORGANIZATION_ID], [PERSON_ID], [ORGANIZATION_ID], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _PERSON_ORGANIZATION_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [PERSON_ORGANIZATION_ID], [PERSON_ID], [ORGANIZATION_ID], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_PERSON_ORGANIZATION_H_ID_SEQ]) as [_PERSON_ORGANIZATION_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_SCHLDT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_SCHLDT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_SCHLDT_I_S_U_TR] ON PIMS_SEC_DEP_HOLDER_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.SEC_DEP_HOLDER_TYPE_CODE = deleted.SEC_DEP_HOLDER_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_SEC_DEP_HOLDER_TYPE
      set "SEC_DEP_HOLDER_TYPE_CODE" = inserted."SEC_DEP_HOLDER_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_SEC_DEP_HOLDER_TYPE
      inner join inserted
      on (PIMS_SEC_DEP_HOLDER_TYPE.SEC_DEP_HOLDER_TYPE_CODE = inserted.SEC_DEP_HOLDER_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPSTS_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PRPSTS_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPSTS_I_S_U_TR] ON PIMS_PROPERTY_STATUS_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROPERTY_STATUS_TYPE_CODE = deleted.PROPERTY_STATUS_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROPERTY_STATUS_TYPE
      set "PROPERTY_STATUS_TYPE_CODE" = inserted."PROPERTY_STATUS_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROPERTY_STATUS_TYPE
      inner join inserted
      on (PIMS_PROPERTY_STATUS_TYPE.PROPERTY_STATUS_TYPE_CODE = inserted.PROPERTY_STATUS_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PROJTR_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PROJTR_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PROJTR_I_S_U_TR] ON PIMS_PROJECT_TIER_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROJECT_TIER_TYPE_CODE = deleted.PROJECT_TIER_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROJECT_TIER_TYPE
      set "PROJECT_TIER_TYPE_CODE" = inserted."PROJECT_TIER_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROJECT_TIER_TYPE
      inner join inserted
      on (PIMS_PROJECT_TIER_TYPE.PROJECT_TIER_TYPE_CODE = inserted.PROJECT_TIER_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_TASK_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_TASK_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_TASK_I_S_I_TR] ON PIMS_TASK INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_TASK ("TASK_ID",
        "TASK_TEMPLATE_ID",
        "ACTIVITY_ID",
        "USER_ID",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "TASK_ID",
        "TASK_TEMPLATE_ID",
        "ACTIVITY_ID",
        "USER_ID",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ORG_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_ORG_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ORG_I_S_I_TR] ON PIMS_ORGANIZATION INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_ORGANIZATION ("ORGANIZATION_ID",
        "PRNT_ORGANIZATION_ID",
        "ADDRESS_ID",
        "REGION_CODE",
        "DISTRICT_CODE",
        "ORGANIZATION_TYPE_CODE",
        "ORG_IDENTIFIER_TYPE_CODE",
        "ORGANIZATION_IDENTIFIER",
        "ORGANIZATION_NAME",
        "WEBSITE",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "ORGANIZATION_ID",
        "PRNT_ORGANIZATION_ID",
        "ADDRESS_ID",
        "REGION_CODE",
        "DISTRICT_CODE",
        "ORGANIZATION_TYPE_CODE",
        "ORG_IDENTIFIER_TYPE_CODE",
        "ORGANIZATION_IDENTIFIER",
        "ORGANIZATION_NAME",
        "WEBSITE",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_LSCATT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_LSCATT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_LSCATT_I_S_I_TR] ON PIMS_LEASE_CATEGORY_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_LEASE_CATEGORY_TYPE ("LEASE_CATEGORY_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "LEASE_CATEGORY_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_INSRNC_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_INSRNC_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_INSRNC_I_S_U_TR] ON PIMS_INSURANCE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.INSURANCE_ID = deleted.INSURANCE_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_INSURANCE
      set "INSURANCE_ID" = inserted."INSURANCE_ID",
        "LEASE_ID" = inserted."LEASE_ID",
        "INSURANCE_TYPE_CODE" = inserted."INSURANCE_TYPE_CODE",
        "INSURER_ORG_ID" = inserted."INSURER_ORG_ID",
        "INSURER_CONTACT_ID" = inserted."INSURER_CONTACT_ID",
        "MOTI_RISK_MGMT_CONTACT_ID" = inserted."MOTI_RISK_MGMT_CONTACT_ID",
        "BCTFA_RISK_MGMT_CONTACT_ID" = inserted."BCTFA_RISK_MGMT_CONTACT_ID",
        "INSURANCE_PAYEE_TYPE_CODE" = inserted."INSURANCE_PAYEE_TYPE_CODE",
        "OTHER_INSURANCE_TYPE" = inserted."OTHER_INSURANCE_TYPE",
        "COVERAGE_DESCRIPTION" = inserted."COVERAGE_DESCRIPTION",
        "COVERAGE_LIMIT" = inserted."COVERAGE_LIMIT",
        "INSURED_VALUE" = inserted."INSURED_VALUE",
        "START_DATE" = inserted."START_DATE",
        "EXPIRY_DATE" = inserted."EXPIRY_DATE",
        "RISK ASSESSMENT_COMPLETED_DATE" = inserted."RISK ASSESSMENT_COMPLETED_DATE",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_INSURANCE
      inner join inserted
      on (PIMS_INSURANCE.INSURANCE_ID = inserted.INSURANCE_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ACRQOR_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_ACRQOR_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ACRQOR_I_S_I_TR] ON PIMS_ACCESS_REQUEST_ORGANIZATION INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_ACCESS_REQUEST_ORGANIZATION ("ACCESS_REQUEST_ORGANIZATION_ID",
        "ORGANIZATION_ID",
        "ACCESS_REQUEST_ID",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "ACCESS_REQUEST_ORGANIZATION_ID",
        "ORGANIZATION_ID",
        "ACCESS_REQUEST_ID",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_WFLMDL_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_WFLMDL_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_WFLMDL_A_S_IUD_TR] ON PIMS_WORKFLOW_MODEL FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_WORKFLOW_MODEL_HIST set END_DATE_HIST = @curr_date where WORKFLOW_MODEL_ID in (select WORKFLOW_MODEL_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_WORKFLOW_MODEL_HIST ([WORKFLOW_MODEL_ID], [WORKFLOW_MODEL_TYPE_CODE], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _WORKFLOW_MODEL_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [WORKFLOW_MODEL_ID], [WORKFLOW_MODEL_TYPE_CODE], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_WORKFLOW_MODEL_H_ID_SEQ]) as [_WORKFLOW_MODEL_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PROVNC_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PROVNC_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PROVNC_I_S_U_TR] ON PIMS_PROVINCE_STATE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROVINCE_STATE_ID = deleted.PROVINCE_STATE_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROVINCE_STATE
      set "PROVINCE_STATE_ID" = inserted."PROVINCE_STATE_ID",
        "COUNTRY_ID" = inserted."COUNTRY_ID",
        "PROVINCE_STATE_CODE" = inserted."PROVINCE_STATE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROVINCE_STATE
      inner join inserted
      on (PIMS_PROVINCE_STATE.PROVINCE_STATE_ID = inserted.PROVINCE_STATE_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPTYP_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PRPTYP_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPTYP_I_S_I_TR] ON PIMS_PROPERTY_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROPERTY_TYPE ("PROPERTY_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "PROPERTY_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRSVFT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PRSVFT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRSVFT_I_S_U_TR] ON PIMS_PROPERTY_SERVICE_FILE_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROPERTY_SERVICE_FILE_TYPE_CODE = deleted.PROPERTY_SERVICE_FILE_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROPERTY_SERVICE_FILE_TYPE
      set "PROPERTY_SERVICE_FILE_TYPE_CODE" = inserted."PROPERTY_SERVICE_FILE_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROPERTY_SERVICE_FILE_TYPE
      inner join inserted
      on (PIMS_PROPERTY_SERVICE_FILE_TYPE.PROPERTY_SERVICE_FILE_TYPE_CODE = inserted.PROPERTY_SERVICE_FILE_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_TSKTAM_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_TSKTAM_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_TSKTAM_A_S_IUD_TR] ON PIMS_TASK_TEMPLATE_ACTIVITY_MODEL FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_TASK_TEMPLATE_ACTIVITY_MODEL_HIST set END_DATE_HIST = @curr_date where TASK_TEMPLATE_ACTIVITY_MODEL_ID in (select TASK_TEMPLATE_ACTIVITY_MODEL_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_TASK_TEMPLATE_ACTIVITY_MODEL_HIST ([TASK_TEMPLATE_ACTIVITY_MODEL_ID], [TASK_TEMPLATE_ID], [ACTIVITY_MODEL_ID], [IS_MANDATORY], [IMPLEMENTATION_ORDER], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _TASK_TEMPLATE_ACTIVITY_MODEL_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [TASK_TEMPLATE_ACTIVITY_MODEL_ID], [TASK_TEMPLATE_ID], [ACTIVITY_MODEL_ID], [IS_MANDATORY], [IMPLEMENTATION_ORDER], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_TASK_TEMPLATE_ACTIVITY_MODEL_H_ID_SEQ]) as [_TASK_TEMPLATE_ACTIVITY_MODEL_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ACTVTY_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_ACTVTY_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ACTVTY_I_S_U_TR] ON PIMS_ACTIVITY INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.ACTIVITY_ID = deleted.ACTIVITY_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_ACTIVITY
      set "ACTIVITY_ID" = inserted."ACTIVITY_ID",
        "PROJECT_ID" = inserted."PROJECT_ID",
        "WORKFLOW_ID" = inserted."WORKFLOW_ID",
        "ACTIVITY_MODEL_ID" = inserted."ACTIVITY_MODEL_ID",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_ACTIVITY
      inner join inserted
      on (PIMS_ACTIVITY.ACTIVITY_ID = inserted.ACTIVITY_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_CNTMTH_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_CNTMTH_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_CNTMTH_A_S_IUD_TR] ON PIMS_CONTACT_METHOD FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_CONTACT_METHOD_HIST set END_DATE_HIST = @curr_date where CONTACT_METHOD_ID in (select CONTACT_METHOD_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_CONTACT_METHOD_HIST ([CONTACT_METHOD_ID], [CONTACT_METHOD_TYPE_CODE], [PERSON_ID], [ORGANIZATION_ID], [CONTACT_METHOD_VALUE], [IS_PREFERRED_METHOD], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _CONTACT_METHOD_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [CONTACT_METHOD_ID], [CONTACT_METHOD_TYPE_CODE], [PERSON_ID], [ORGANIZATION_ID], [CONTACT_METHOD_VALUE], [IS_PREFERRED_METHOD], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_CONTACT_METHOD_H_ID_SEQ]) as [_CONTACT_METHOD_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRJPRP_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PRJPRP_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRJPRP_I_S_I_TR] ON PIMS_PROJECT_PROPERTY INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROJECT_PROPERTY ("PROJECT_PROPERTY_ID",
        "PROJECT_ID",
        "PROPERTY_ID",
        "IS_DISABLED",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USER_DIRECTORY",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USERID",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USERID",
        "CONCURRENCY_CONTROL_NUMBER")
      select "PROJECT_PROPERTY_ID",
        "PROJECT_ID",
        "PROPERTY_ID",
        "IS_DISABLED",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USER_DIRECTORY",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USERID",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USERID",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PIMPRV_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_PIMPRV_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PIMPRV_A_S_IUD_TR] ON PIMS_PROPERTY_IMPROVEMENT FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_PROPERTY_IMPROVEMENT_HIST set END_DATE_HIST = @curr_date where PROPERTY_IMPROVEMENT_ID in (select PROPERTY_IMPROVEMENT_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_PROPERTY_IMPROVEMENT_HIST ([PROPERTY_IMPROVEMENT_ID], [PROPERTY_LEASE_ID], [PROPERTY_IMPROVEMENT_TYPE_CODE], [PROPERTY_IMPROVEMENT_UOM_TYPE_CODE], [IMPROVEMENT_DESCRIPTION], [STRUCTURE_SIZE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _PROPERTY_IMPROVEMENT_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [PROPERTY_IMPROVEMENT_ID], [PROPERTY_LEASE_ID], [PROPERTY_IMPROVEMENT_TYPE_CODE], [PROPERTY_IMPROVEMENT_UOM_TYPE_CODE], [IMPROVEMENT_DESCRIPTION], [STRUCTURE_SIZE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_PROPERTY_IMPROVEMENT_H_ID_SEQ]) as [_PROPERTY_IMPROVEMENT_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_WFLMDL_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_WFLMDL_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_WFLMDL_I_S_I_TR] ON PIMS_WORKFLOW_MODEL INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_WORKFLOW_MODEL ("WORKFLOW_MODEL_ID",
        "WORKFLOW_MODEL_TYPE_CODE",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "WORKFLOW_MODEL_ID",
        "WORKFLOW_MODEL_TYPE_CODE",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PROPLS_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PROPLS_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PROPLS_I_S_I_TR] ON PIMS_PROPERTY_LEASE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROPERTY_LEASE ("PROPERTY_LEASE_ID",
        "PROPERTY_ID",
        "LEASE_ID",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "PROPERTY_LEASE_ID",
        "PROPERTY_ID",
        "LEASE_ID",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPSVC_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_PRPSVC_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPSVC_A_S_IUD_TR] ON PIMS_PROPERTY_SERVICE_FILE FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_PROPERTY_SERVICE_FILE_HIST set END_DATE_HIST = @curr_date where PROPERTY_SERVICE_FILE_ID in (select PROPERTY_SERVICE_FILE_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_PROPERTY_SERVICE_FILE_HIST ([PROPERTY_SERVICE_FILE_ID], [PROPERTY_SERVICE_FILE_TYPE_CODE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _PROPERTY_SERVICE_FILE_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [PROPERTY_SERVICE_FILE_ID], [PROPERTY_SERVICE_FILE_TYPE_CODE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_PROPERTY_SERVICE_FILE_H_ID_SEQ]) as [_PROPERTY_SERVICE_FILE_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRJSTY_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PRJSTY_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRJSTY_I_S_I_TR] ON PIMS_PROJECT_STATUS_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROJECT_STATUS_TYPE ("PROJECT_STATUS_TYPE_CODE",
        "CODE_GROUP",
        "DESCRIPTION",
        "TEXT",
        "IS_MILESTONE",
        "IS_TERMINAL",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "PROJECT_STATUS_TYPE_CODE",
        "CODE_GROUP",
        "DESCRIPTION",
        "TEXT",
        "IS_MILESTONE",
        "IS_TERMINAL",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPACT_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_PRPACT_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPACT_A_S_IUD_TR] ON PIMS_PROPERTY_ACTIVITY FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_PROPERTY_ACTIVITY_HIST set END_DATE_HIST = @curr_date where PROPERTY_ACTIVITY_ID in (select PROPERTY_ACTIVITY_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_PROPERTY_ACTIVITY_HIST ([PROPERTY_ACTIVITY_ID], [ACTIVITY_ID], [PROPERTY_ID], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _PROPERTY_ACTIVITY_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [PROPERTY_ACTIVITY_ID], [ACTIVITY_ID], [PROPERTY_ID], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_PROPERTY_ACTIVITY_H_ID_SEQ]) as [_PROPERTY_ACTIVITY_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ROLE_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_ROLE_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ROLE_A_S_IUD_TR] ON PIMS_ROLE FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_ROLE_HIST set END_DATE_HIST = @curr_date where ROLE_ID in (select ROLE_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_ROLE_HIST ([ROLE_ID], [ROLE_UID], [KEYCLOAK_GROUP_ID], [NAME], [DESCRIPTION], [IS_PUBLIC], [IS_DISABLED], [SORT_ORDER], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _ROLE_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [ROLE_ID], [ROLE_UID], [KEYCLOAK_GROUP_ID], [NAME], [DESCRIPTION], [IS_PUBLIC], [IS_DISABLED], [SORT_ORDER], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_ROLE_H_ID_SEQ]) as [_ROLE_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_INSRNC_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_INSRNC_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_INSRNC_I_S_I_TR] ON PIMS_INSURANCE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_INSURANCE ("INSURANCE_ID",
        "LEASE_ID",
        "INSURANCE_TYPE_CODE",
        "INSURER_ORG_ID",
        "INSURER_CONTACT_ID",
        "MOTI_RISK_MGMT_CONTACT_ID",
        "BCTFA_RISK_MGMT_CONTACT_ID",
        "INSURANCE_PAYEE_TYPE_CODE",
        "OTHER_INSURANCE_TYPE",
        "COVERAGE_DESCRIPTION",
        "COVERAGE_LIMIT",
        "INSURED_VALUE",
        "START_DATE",
        "EXPIRY_DATE",
        "RISK ASSESSMENT_COMPLETED_DATE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "INSURANCE_ID",
        "LEASE_ID",
        "INSURANCE_TYPE_CODE",
        "INSURER_ORG_ID",
        "INSURER_CONTACT_ID",
        "MOTI_RISK_MGMT_CONTACT_ID",
        "BCTFA_RISK_MGMT_CONTACT_ID",
        "INSURANCE_PAYEE_TYPE_CODE",
        "OTHER_INSURANCE_TYPE",
        "COVERAGE_DESCRIPTION",
        "COVERAGE_LIMIT",
        "INSURED_VALUE",
        "START_DATE",
        "EXPIRY_DATE",
        "RISK ASSESSMENT_COMPLETED_DATE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_LSPMTF_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_LSPMTF_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_LSPMTF_I_S_I_TR] ON PIMS_LEASE_PMT_FREQ_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_LEASE_PMT_FREQ_TYPE ("LEASE_PMT_FREQ_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "LEASE_PMT_FREQ_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_SPDCLT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_SPDCLT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_SPDCLT_I_S_I_TR] ON PIMS_SURPLUS_DECLARATION_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_SURPLUS_DECLARATION_TYPE ("SURPLUS_DECLARATION_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "SURPLUS_DECLARATION_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_SECDEP_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_SECDEP_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_SECDEP_I_S_I_TR] ON PIMS_SECURITY_DEPOSIT INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_SECURITY_DEPOSIT ("SECURITY_DEPOSIT_ID",
        "LEASE_ID",
        "SEC_DEP_HOLDER_TYPE_CODE",
        "SECURITY_DEPOSIT_TYPE_CODE",
        "DESCRIPTION",
        "AMOUNT_PAID",
        "TOTAL_AMOUNT",
        "DEPOSIT_DATE",
        "ANNUAL_INTEREST_RATE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "SECURITY_DEPOSIT_ID",
        "LEASE_ID",
        "SEC_DEP_HOLDER_TYPE_CODE",
        "SECURITY_DEPOSIT_TYPE_CODE",
        "DESCRIPTION",
        "AMOUNT_PAID",
        "TOTAL_AMOUNT",
        "DEPOSIT_DATE",
        "ANNUAL_INTEREST_RATE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_SPDCLT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_SPDCLT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_SPDCLT_I_S_U_TR] ON PIMS_SURPLUS_DECLARATION_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.SURPLUS_DECLARATION_TYPE_CODE = deleted.SURPLUS_DECLARATION_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_SURPLUS_DECLARATION_TYPE
      set "SURPLUS_DECLARATION_TYPE_CODE" = inserted."SURPLUS_DECLARATION_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_SURPLUS_DECLARATION_TYPE
      inner join inserted
      on (PIMS_SURPLUS_DECLARATION_TYPE.SURPLUS_DECLARATION_TYPE_CODE = inserted.SURPLUS_DECLARATION_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRSVFT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PRSVFT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRSVFT_I_S_I_TR] ON PIMS_PROPERTY_SERVICE_FILE_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROPERTY_SERVICE_FILE_TYPE ("PROPERTY_SERVICE_FILE_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "PROPERTY_SERVICE_FILE_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_TSKTMP_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_TSKTMP_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_TSKTMP_A_S_IUD_TR] ON PIMS_TASK_TEMPLATE FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_TASK_TEMPLATE_HIST set END_DATE_HIST = @curr_date where TASK_TEMPLATE_ID in (select TASK_TEMPLATE_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_TASK_TEMPLATE_HIST ([TASK_TEMPLATE_ID], [TASK_TEMPLATE_TYPE_CODE], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _TASK_TEMPLATE_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [TASK_TEMPLATE_ID], [TASK_TEMPLATE_TYPE_CODE], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_TASK_TEMPLATE_H_ID_SEQ]) as [_TASK_TEMPLATE_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_LSCATT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_LSCATT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_LSCATT_I_S_U_TR] ON PIMS_LEASE_CATEGORY_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.LEASE_CATEGORY_TYPE_CODE = deleted.LEASE_CATEGORY_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_LEASE_CATEGORY_TYPE
      set "LEASE_CATEGORY_TYPE_CODE" = inserted."LEASE_CATEGORY_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_LEASE_CATEGORY_TYPE
      inner join inserted
      on (PIMS_LEASE_CATEGORY_TYPE.LEASE_CATEGORY_TYPE_CODE = inserted.LEASE_CATEGORY_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ORG_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_ORG_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ORG_I_S_U_TR] ON PIMS_ORGANIZATION INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.ORGANIZATION_ID = deleted.ORGANIZATION_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_ORGANIZATION
      set "ORGANIZATION_ID" = inserted."ORGANIZATION_ID",
        "PRNT_ORGANIZATION_ID" = inserted."PRNT_ORGANIZATION_ID",
        "ADDRESS_ID" = inserted."ADDRESS_ID",
        "REGION_CODE" = inserted."REGION_CODE",
        "DISTRICT_CODE" = inserted."DISTRICT_CODE",
        "ORGANIZATION_TYPE_CODE" = inserted."ORGANIZATION_TYPE_CODE",
        "ORG_IDENTIFIER_TYPE_CODE" = inserted."ORG_IDENTIFIER_TYPE_CODE",
        "ORGANIZATION_IDENTIFIER" = inserted."ORGANIZATION_IDENTIFIER",
        "ORGANIZATION_NAME" = inserted."ORGANIZATION_NAME",
        "WEBSITE" = inserted."WEBSITE",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_ORGANIZATION
      inner join inserted
      on (PIMS_ORGANIZATION.ORGANIZATION_ID = inserted.ORGANIZATION_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_SECDPT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_SECDPT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_SECDPT_I_S_I_TR] ON PIMS_SECURITY_DEPOSIT_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_SECURITY_DEPOSIT_TYPE ("SECURITY_DEPOSIT_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "SECURITY_DEPOSIT_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_TSKTMP_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_TSKTMP_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_TSKTMP_I_S_U_TR] ON PIMS_TASK_TEMPLATE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.TASK_TEMPLATE_ID = deleted.TASK_TEMPLATE_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_TASK_TEMPLATE
      set "TASK_TEMPLATE_ID" = inserted."TASK_TEMPLATE_ID",
        "TASK_TEMPLATE_TYPE_CODE" = inserted."TASK_TEMPLATE_TYPE_CODE",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_TASK_TEMPLATE
      inner join inserted
      on (PIMS_TASK_TEMPLATE.TASK_TEMPLATE_ID = inserted.TASK_TEMPLATE_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPRTY_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_PRPRTY_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPRTY_A_S_IUD_TR] ON PIMS_PROPERTY FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_PROPERTY_HIST set END_DATE_HIST = @curr_date where PROPERTY_ID in (select PROPERTY_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_PROPERTY_HIST ([PROPERTY_ID], [PROPERTY_MANAGER_ID], [PROP_MGMT_ORG_ID], [PROPERTY_TYPE_CODE], [PROPERTY_CLASSIFICATION_TYPE_CODE], [ADDRESS_ID], [REGION_CODE], [DISTRICT_CODE], [PROPERTY_TENURE_TYPE_CODE], [PROPERTY_AREA_UNIT_TYPE_CODE], [PROPERTY_STATUS_TYPE_CODE], [SURPLUS_DECLARATION_TYPE_CODE], [PROPERTY_DATA_SOURCE_TYPE_CODE], [PROPERTY_DATA_SOURCE_EFFECTIVE_DATE], [NAME], [DESCRIPTION], [PID], [PIN], [LAND_AREA], [ENCUMBRANCE_REASON], [SURPLUS_DECLARATION_COMMENT], [SURPLUS_DECLARATION_DATE], [IS_OWNED], [IS_PROPERTY_OF_INTEREST], [IS_VISIBLE_TO_OTHER_AGENCIES], [IS_SENSITIVE], [ZONING], [ZONING_POTENTIAL], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _PROPERTY_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [PROPERTY_ID], [PROPERTY_MANAGER_ID], [PROP_MGMT_ORG_ID], [PROPERTY_TYPE_CODE], [PROPERTY_CLASSIFICATION_TYPE_CODE], [ADDRESS_ID], [REGION_CODE], [DISTRICT_CODE], [PROPERTY_TENURE_TYPE_CODE], [PROPERTY_AREA_UNIT_TYPE_CODE], [PROPERTY_STATUS_TYPE_CODE], [SURPLUS_DECLARATION_TYPE_CODE], [PROPERTY_DATA_SOURCE_TYPE_CODE], [PROPERTY_DATA_SOURCE_EFFECTIVE_DATE], [NAME], [DESCRIPTION], [PID], [PIN], [LAND_AREA], [ENCUMBRANCE_REASON], [SURPLUS_DECLARATION_COMMENT], [SURPLUS_DECLARATION_DATE], [IS_OWNED], [IS_PROPERTY_OF_INTEREST], [IS_VISIBLE_TO_OTHER_AGENCIES], [IS_SENSITIVE], [ZONING], [ZONING_POTENTIAL], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_PROPERTY_H_ID_SEQ]) as [_PROPERTY_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PIMPRU_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PIMPRU_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PIMPRU_I_S_U_TR] ON PIMS_PROPERTY_IMPROVEMENT_UOM_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROPERTY_IMPROVEMENT_UOM_TYPE_CODE = deleted.PROPERTY_IMPROVEMENT_UOM_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROPERTY_IMPROVEMENT_UOM_TYPE
      set "PROPERTY_IMPROVEMENT_UOM_TYPE_CODE" = inserted."PROPERTY_IMPROVEMENT_UOM_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROPERTY_IMPROVEMENT_UOM_TYPE
      inner join inserted
      on (PIMS_PROPERTY_IMPROVEMENT_UOM_TYPE.PROPERTY_IMPROVEMENT_UOM_TYPE_CODE = inserted.PROPERTY_IMPROVEMENT_UOM_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPRSF_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PRPRSF_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPRSF_I_S_I_TR] ON PIMS_PROPERTY_PROPERTY_SERVICE_FILE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROPERTY_PROPERTY_SERVICE_FILE ("PROPERTY_PROPERTY_SERVICE_FILE_ID",
        "PROPERTY_ID",
        "PROPERTY_SERVICE_FILE_ID",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "PROPERTY_PROPERTY_SERVICE_FILE_ID",
        "PROPERTY_ID",
        "PROPERTY_SERVICE_FILE_ID",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPTNR_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PRPTNR_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPTNR_I_S_I_TR] ON PIMS_PROPERTY_TENURE_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROPERTY_TENURE_TYPE ("PROPERTY_TENURE_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "PROPERTY_TENURE_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PERSON_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_PERSON_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PERSON_A_S_IUD_TR] ON PIMS_PERSON FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_PERSON_HIST set END_DATE_HIST = @curr_date where PERSON_ID in (select PERSON_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_PERSON_HIST ([PERSON_ID], [ADDRESS_ID], [SURNAME], [FIRST_NAME], [MIDDLE_NAMES], [NAME_SUFFIX], [BIRTH_DATE], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _PERSON_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [PERSON_ID], [ADDRESS_ID], [SURNAME], [FIRST_NAME], [MIDDLE_NAMES], [NAME_SUFFIX], [BIRTH_DATE], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_PERSON_H_ID_SEQ]) as [_PERSON_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_LSSRTY_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_LSSRTY_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_LSSRTY_I_S_I_TR] ON PIMS_LESSOR_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_LESSOR_TYPE ("LESSOR_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "LESSOR_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_LSPRTY_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_LSPRTY_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_LSPRTY_I_S_I_TR] ON PIMS_LEASE_PAY_RVBL_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_LEASE_PAY_RVBL_TYPE ("LEASE_PAY_RVBL_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "LEASE_PAY_RVBL_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPRSF_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_PRPRSF_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPRSF_A_S_IUD_TR] ON PIMS_PROPERTY_PROPERTY_SERVICE_FILE FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_PROPERTY_PROPERTY_SERVICE_FILE_HIST set END_DATE_HIST = @curr_date where PROPERTY_PROPERTY_SERVICE_FILE_ID in (select PROPERTY_PROPERTY_SERVICE_FILE_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_PROPERTY_PROPERTY_SERVICE_FILE_HIST ([PROPERTY_PROPERTY_SERVICE_FILE_ID], [PROPERTY_ID], [PROPERTY_SERVICE_FILE_ID], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _PROPERTY_PROPERTY_SERVICE_FILE_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [PROPERTY_PROPERTY_SERVICE_FILE_ID], [PROPERTY_ID], [PROPERTY_SERVICE_FILE_ID], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_PROPERTY_PROPERTY_SERVICE_FILE_H_ID_SEQ]) as [_PROPERTY_PROPERTY_SERVICE_FILE_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_LELIST_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_LELIST_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_LELIST_I_S_I_TR] ON PIMS_LEASE_LICENSE_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_LEASE_LICENSE_TYPE ("LEASE_LICENSE_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "LEASE_LICENSE_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRJRSK_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PRJRSK_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRJRSK_I_S_I_TR] ON PIMS_PROJECT_RISK_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROJECT_RISK_TYPE ("PROJECT_RISK_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "PROJECT_RISK_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PROPLS_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_PROPLS_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PROPLS_A_S_IUD_TR] ON PIMS_PROPERTY_LEASE FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_PROPERTY_LEASE_HIST set END_DATE_HIST = @curr_date where PROPERTY_LEASE_ID in (select PROPERTY_LEASE_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_PROPERTY_LEASE_HIST ([PROPERTY_LEASE_ID], [PROPERTY_ID], [LEASE_ID], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _PROPERTY_LEASE_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [PROPERTY_LEASE_ID], [PROPERTY_ID], [LEASE_ID], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_PROPERTY_LEASE_H_ID_SEQ]) as [_PROPERTY_LEASE_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ARQSTT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_ARQSTT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ARQSTT_I_S_U_TR] ON PIMS_ACCESS_REQUEST_STATUS_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.ACCESS_REQUEST_STATUS_TYPE_CODE = deleted.ACCESS_REQUEST_STATUS_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_ACCESS_REQUEST_STATUS_TYPE
      set "ACCESS_REQUEST_STATUS_TYPE_CODE" = inserted."ACCESS_REQUEST_STATUS_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_ACCESS_REQUEST_STATUS_TYPE
      inner join inserted
      on (PIMS_ACCESS_REQUEST_STATUS_TYPE.ACCESS_REQUEST_STATUS_TYPE_CODE = inserted.ACCESS_REQUEST_STATUS_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_CNTRY_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_CNTRY_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_CNTRY_I_S_I_TR] ON PIMS_COUNTRY INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_COUNTRY ("COUNTRY_ID",
        "COUNTRY_CODE",
        "DESCRIPTION",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "COUNTRY_ID",
        "COUNTRY_CODE",
        "DESCRIPTION",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPTAX_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_PRPTAX_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPTAX_A_S_IUD_TR] ON PIMS_PROPERTY_TAX FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_PROPERTY_TAX_HIST set END_DATE_HIST = @curr_date where PROPERTY_TAX_ID in (select PROPERTY_TAX_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_PROPERTY_TAX_HIST ([PROPERTY_TAX_ID], [PROPERTY_ID], [PROPERTY_TAX_REMIT_TYPE_CODE], [TAX_FOLIO_NO], [PAYMENT_AMOUNT], [LAST_PAYMENT_DATE], [PAYMENT_NOTES], [BCTFA_NOTIFICATION_DATE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _PROPERTY_TAX_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [PROPERTY_TAX_ID], [PROPERTY_ID], [PROPERTY_TAX_REMIT_TYPE_CODE], [TAX_FOLIO_NO], [PAYMENT_AMOUNT], [LAST_PAYMENT_DATE], [PAYMENT_NOTES], [BCTFA_NOTIFICATION_DATE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_PROPERTY_TAX_H_ID_SEQ]) as [_PROPERTY_TAX_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_INSPYT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_INSPYT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_INSPYT_I_S_U_TR] ON PIMS_INSURANCE_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.INSURANCE_TYPE_CODE = deleted.INSURANCE_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_INSURANCE_TYPE
      set "INSURANCE_TYPE_CODE" = inserted."INSURANCE_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_INSURANCE_TYPE
      inner join inserted
      on (PIMS_INSURANCE_TYPE.INSURANCE_TYPE_CODE = inserted.INSURANCE_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_USRORG_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_USRORG_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_USRORG_I_S_U_TR] ON PIMS_USER_ORGANIZATION INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.USER_ORGANIZATION_ID = deleted.USER_ORGANIZATION_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_USER_ORGANIZATION
      set "USER_ORGANIZATION_ID" = inserted."USER_ORGANIZATION_ID",
        "ORGANIZATION_ID" = inserted."ORGANIZATION_ID",
        "USER_ID" = inserted."USER_ID",
        "ROLE_ID" = inserted."ROLE_ID",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_USER_ORGANIZATION
      inner join inserted
      on (PIMS_USER_ORGANIZATION.USER_ORGANIZATION_ID = inserted.USER_ORGANIZATION_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_SECDPT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_SECDPT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_SECDPT_I_S_U_TR] ON PIMS_SECURITY_DEPOSIT_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.SECURITY_DEPOSIT_TYPE_CODE = deleted.SECURITY_DEPOSIT_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_SECURITY_DEPOSIT_TYPE
      set "SECURITY_DEPOSIT_TYPE_CODE" = inserted."SECURITY_DEPOSIT_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_SECURITY_DEPOSIT_TYPE
      inner join inserted
      on (PIMS_SECURITY_DEPOSIT_TYPE.SECURITY_DEPOSIT_TYPE_CODE = inserted.SECURITY_DEPOSIT_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_CLMTYP_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_CLMTYP_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_CLMTYP_I_S_U_TR] ON PIMS_CLAIM INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.CLAIM_ID = deleted.CLAIM_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_CLAIM
      set "CLAIM_ID" = inserted."CLAIM_ID",
        "CLAIM_UID" = inserted."CLAIM_UID",
        "KEYCLOAK_ROLE_ID" = inserted."KEYCLOAK_ROLE_ID",
        "NAME" = inserted."NAME",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_CLAIM
      inner join inserted
      on (PIMS_CLAIM.CLAIM_ID = inserted.CLAIM_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_TSKTMP_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_TSKTMP_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_TSKTMP_I_S_I_TR] ON PIMS_TASK_TEMPLATE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_TASK_TEMPLATE ("TASK_TEMPLATE_ID",
        "TASK_TEMPLATE_TYPE_CODE",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "TASK_TEMPLATE_ID",
        "TASK_TEMPLATE_TYPE_CODE",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ADDRSS_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_ADDRSS_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ADDRSS_A_S_IUD_TR] ON PIMS_ADDRESS FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_ADDRESS_HIST set END_DATE_HIST = @curr_date where ADDRESS_ID in (select ADDRESS_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_ADDRESS_HIST ([ADDRESS_ID], [ADDRESS_USAGE_TYPE_CODE], [REGION_CODE], [DISTRICT_CODE], [PROVINCE_STATE_ID], [COUNTRY_ID], [STREET_ADDRESS_1], [STREET_ADDRESS_2], [STREET_ADDRESS_3], [MUNICIPALITY_NAME], [POSTAL_CODE], [LATITUDE], [LONGITUDE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _ADDRESS_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [ADDRESS_ID], [ADDRESS_USAGE_TYPE_CODE], [REGION_CODE], [DISTRICT_CODE], [PROVINCE_STATE_ID], [COUNTRY_ID], [STREET_ADDRESS_1], [STREET_ADDRESS_2], [STREET_ADDRESS_3], [MUNICIPALITY_NAME], [POSTAL_CODE], [LATITUDE], [LONGITUDE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_ADDRESS_H_ID_SEQ]) as [_ADDRESS_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRPRSF_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PRPRSF_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRPRSF_I_S_U_TR] ON PIMS_PROPERTY_PROPERTY_SERVICE_FILE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROPERTY_PROPERTY_SERVICE_FILE_ID = deleted.PROPERTY_PROPERTY_SERVICE_FILE_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROPERTY_PROPERTY_SERVICE_FILE
      set "PROPERTY_PROPERTY_SERVICE_FILE_ID" = inserted."PROPERTY_PROPERTY_SERVICE_FILE_ID",
        "PROPERTY_ID" = inserted."PROPERTY_ID",
        "PROPERTY_SERVICE_FILE_ID" = inserted."PROPERTY_SERVICE_FILE_ID",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROPERTY_PROPERTY_SERVICE_FILE
      inner join inserted
      on (PIMS_PROPERTY_PROPERTY_SERVICE_FILE.PROPERTY_PROPERTY_SERVICE_FILE_ID = inserted.PROPERTY_PROPERTY_SERVICE_FILE_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_USER_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_USER_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_USER_A_S_IUD_TR] ON PIMS_USER FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_USER_HIST set END_DATE_HIST = @curr_date where USER_ID in (select USER_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_USER_HIST ([USER_ID], [PERSON_ID], [BUSINESS_IDENTIFIER_VALUE], [GUID_IDENTIFIER_VALUE], [POSITION], [NOTE], [LAST_LOGIN], [APPROVED_BY_ID], [ISSUE_DATE], [EXPIRY_DATE], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _USER_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [USER_ID], [PERSON_ID], [BUSINESS_IDENTIFIER_VALUE], [GUID_IDENTIFIER_VALUE], [POSITION], [NOTE], [LAST_LOGIN], [APPROVED_BY_ID], [ISSUE_DATE], [EXPIRY_DATE], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_USER_H_ID_SEQ]) as [_USER_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ORGTYP_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_ORGTYP_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ORGTYP_I_S_I_TR] ON PIMS_ORGANIZATION_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_ORGANIZATION_TYPE ("ORGANIZATION_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "ORGANIZATION_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PRJTYP_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PRJTYP_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PRJTYP_I_S_U_TR] ON PIMS_PROJECT_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROJECT_TYPE_CODE = deleted.PROJECT_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROJECT_TYPE
      set "PROJECT_TYPE_CODE" = inserted."PROJECT_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROJECT_TYPE
      inner join inserted
      on (PIMS_PROJECT_TYPE.PROJECT_TYPE_CODE = inserted.PROJECT_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ACTVTY_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_ACTVTY_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ACTVTY_A_S_IUD_TR] ON PIMS_ACTIVITY FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_ACTIVITY_HIST set END_DATE_HIST = @curr_date where ACTIVITY_ID in (select ACTIVITY_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_ACTIVITY_HIST ([ACTIVITY_ID], [PROJECT_ID], [WORKFLOW_ID], [ACTIVITY_MODEL_ID], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _ACTIVITY_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [ACTIVITY_ID], [PROJECT_ID], [WORKFLOW_ID], [ACTIVITY_MODEL_ID], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_ACTIVITY_H_ID_SEQ]) as [_ACTIVITY_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_CLMTYP_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_CLMTYP_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_CLMTYP_A_S_IUD_TR] ON PIMS_CLAIM FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_CLAIM_HIST set END_DATE_HIST = @curr_date where CLAIM_ID in (select CLAIM_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_CLAIM_HIST ([CLAIM_ID], [CLAIM_UID], [KEYCLOAK_ROLE_ID], [NAME], [DESCRIPTION], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _CLAIM_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [CLAIM_ID], [CLAIM_UID], [KEYCLOAK_ROLE_ID], [NAME], [DESCRIPTION], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_CLAIM_H_ID_SEQ]) as [_CLAIM_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ORG_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_ORG_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ORG_A_S_IUD_TR] ON PIMS_ORGANIZATION FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_ORGANIZATION_HIST set END_DATE_HIST = @curr_date where ORGANIZATION_ID in (select ORGANIZATION_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_ORGANIZATION_HIST ([ORGANIZATION_ID], [PRNT_ORGANIZATION_ID], [ADDRESS_ID], [REGION_CODE], [DISTRICT_CODE], [ORGANIZATION_TYPE_CODE], [ORG_IDENTIFIER_TYPE_CODE], [ORGANIZATION_IDENTIFIER], [ORGANIZATION_NAME], [WEBSITE], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _ORGANIZATION_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [ORGANIZATION_ID], [PRNT_ORGANIZATION_ID], [ADDRESS_ID], [REGION_CODE], [DISTRICT_CODE], [ORGANIZATION_TYPE_CODE], [ORG_IDENTIFIER_TYPE_CODE], [ORGANIZATION_IDENTIFIER], [ORGANIZATION_NAME], [WEBSITE], [IS_DISABLED], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_ORGANIZATION_H_ID_SEQ]) as [_ORGANIZATION_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PIMPRU_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_PIMPRU_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PIMPRU_I_S_I_TR] ON PIMS_PROPERTY_IMPROVEMENT_UOM_TYPE INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_PROPERTY_IMPROVEMENT_UOM_TYPE ("PROPERTY_IMPROVEMENT_UOM_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "PROPERTY_IMPROVEMENT_UOM_TYPE_CODE",
        "DESCRIPTION",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_PROJNT_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_PROJNT_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_PROJNT_I_S_U_TR] ON PIMS_PROJECT_NOTE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.PROJECT_NOTE_ID = deleted.PROJECT_NOTE_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_PROJECT_NOTE
      set "PROJECT_NOTE_ID" = inserted."PROJECT_NOTE_ID",
        "PROJECT_ID" = inserted."PROJECT_ID",
        "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_PROJECT_NOTE
      inner join inserted
      on (PIMS_PROJECT_NOTE.PROJECT_NOTE_ID = inserted.PROJECT_NOTE_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_TENANT_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_TENANT_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_TENANT_I_S_I_TR] ON PIMS_LEASE_TENANT INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_LEASE_TENANT ("LEASE_TENANT_ID",
        "LEASE_ID",
        "PERSON_ID",
        "ORGANIZATION_ID",
        "LESSOR_TYPE_CODE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "LEASE_TENANT_ID",
        "LEASE_ID",
        "PERSON_ID",
        "ORGANIZATION_ID",
        "LESSOR_TYPE_CODE",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_LSSRTY_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_LSSRTY_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_LSSRTY_I_S_U_TR] ON PIMS_LESSOR_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.LESSOR_TYPE_CODE = deleted.LESSOR_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_LESSOR_TYPE
      set "LESSOR_TYPE_CODE" = inserted."LESSOR_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_LESSOR_TYPE
      inner join inserted
      on (PIMS_LESSOR_TYPE.LESSOR_TYPE_CODE = inserted.LESSOR_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ACRQST_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_ACRQST_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ACRQST_A_S_IUD_TR] ON PIMS_ACCESS_REQUEST FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_ACCESS_REQUEST_HIST set END_DATE_HIST = @curr_date where ACCESS_REQUEST_ID in (select ACCESS_REQUEST_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_ACCESS_REQUEST_HIST ([ACCESS_REQUEST_ID], [USER_ID], [ROLE_ID], [ACCESS_REQUEST_STATUS_TYPE_CODE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _ACCESS_REQUEST_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [ACCESS_REQUEST_ID], [USER_ID], [ROLE_ID], [ACCESS_REQUEST_STATUS_TYPE_CODE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_ACCESS_REQUEST_H_ID_SEQ]) as [_ACCESS_REQUEST_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_CNTRY_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_CNTRY_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_CNTRY_I_S_U_TR] ON PIMS_COUNTRY INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.COUNTRY_ID = deleted.COUNTRY_ID)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_COUNTRY
      set "COUNTRY_ID" = inserted."COUNTRY_ID",
        "COUNTRY_CODE" = inserted."COUNTRY_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_COUNTRY
      inner join inserted
      on (PIMS_COUNTRY.COUNTRY_ID = inserted.COUNTRY_ID);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_REGION_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_REGION_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_REGION_I_S_I_TR] ON PIMS_REGION INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_REGION ("REGION_CODE",
        "REGION_NAME",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER")
      select "REGION_CODE",
        "REGION_NAME",
        "IS_DISABLED",
        "DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_LELIST_I_S_U_TR
  PRINT N'Create trigger dbo.PIMS_LELIST_I_S_U_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_LELIST_I_S_U_TR] ON PIMS_LEASE_LICENSE_TYPE INSTEAD OF UPDATE AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- validate concurrency control
    if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.LEASE_LICENSE_TYPE_CODE = deleted.LEASE_LICENSE_TYPE_CODE)
      raiserror('CONCURRENCY FAILURE.',16,1)
  
  
    -- update statement
    update PIMS_LEASE_LICENSE_TYPE
      set "LEASE_LICENSE_TYPE_CODE" = inserted."LEASE_LICENSE_TYPE_CODE",
        "DESCRIPTION" = inserted."DESCRIPTION",
        "IS_DISABLED" = inserted."IS_DISABLED",
        "DISPLAY_ORDER" = inserted."DISPLAY_ORDER",
        "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
      , DB_LAST_UPDATE_TIMESTAMP = getutcdate()
      , DB_LAST_UPDATE_USERID = user_name()
      from PIMS_LEASE_LICENSE_TYPE
      inner join inserted
      on (PIMS_LEASE_LICENSE_TYPE.LEASE_LICENSE_TYPE_CODE = inserted.LEASE_LICENSE_TYPE_CODE);
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_TENANT_A_S_IUD_TR
  PRINT N'Create trigger dbo.PIMS_TENANT_A_S_IUD_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_TENANT_A_S_IUD_TR] ON PIMS_LEASE_TENANT FOR INSERT, UPDATE, DELETE AS
  SET NOCOUNT ON
  BEGIN TRY
  DECLARE @curr_date datetime;
  SET @curr_date = getutcdate();
    IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) 
      RETURN;
  
    -- historical
    IF EXISTS(SELECT * FROM deleted)
      update PIMS_LEASE_TENANT_HIST set END_DATE_HIST = @curr_date where LEASE_TENANT_ID in (select LEASE_TENANT_ID from deleted) and END_DATE_HIST is null;
    
    IF EXISTS(SELECT * FROM inserted)
      insert into PIMS_LEASE_TENANT_HIST ([LEASE_TENANT_ID], [LEASE_ID], [PERSON_ID], [ORGANIZATION_ID], [LESSOR_TYPE_CODE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], _LEASE_TENANT_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
        select [LEASE_TENANT_ID], [LEASE_ID], [PERSON_ID], [ORGANIZATION_ID], [LESSOR_TYPE_CODE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_CREATE_TIMESTAMP], [DB_CREATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], (next value for [dbo].[PIMS_LEASE_TENANT_H_ID_SEQ]) as [_LEASE_TENANT_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_ACTVTY_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_ACTVTY_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_ACTVTY_I_S_I_TR] ON PIMS_ACTIVITY INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_ACTIVITY ("ACTIVITY_ID",
        "PROJECT_ID",
        "WORKFLOW_ID",
        "ACTIVITY_MODEL_ID",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "ACTIVITY_ID",
        "PROJECT_ID",
        "WORKFLOW_ID",
        "ACTIVITY_MODEL_ID",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_USRORG_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_USRORG_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_USRORG_I_S_I_TR] ON PIMS_USER_ORGANIZATION INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_USER_ORGANIZATION ("USER_ORGANIZATION_ID",
        "ORGANIZATION_ID",
        "USER_ID",
        "ROLE_ID",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "USER_ORGANIZATION_ID",
        "ORGANIZATION_ID",
        "USER_ID",
        "ROLE_ID",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create trigger dbo.PIMS_CLMTYP_I_S_I_TR
  PRINT N'Create trigger dbo.PIMS_CLMTYP_I_S_I_TR'
  GO
  CREATE TRIGGER [dbo].[PIMS_CLMTYP_I_S_I_TR] ON PIMS_CLAIM INSTEAD OF INSERT AS
  SET NOCOUNT ON
  BEGIN TRY
    IF NOT EXISTS(SELECT * FROM inserted) 
      RETURN;
  
    
    insert into PIMS_CLAIM ("CLAIM_ID",
        "CLAIM_UID",
        "KEYCLOAK_ROLE_ID",
        "NAME",
        "DESCRIPTION",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY")
      select "CLAIM_ID",
        "CLAIM_UID",
        "KEYCLOAK_ROLE_ID",
        "NAME",
        "DESCRIPTION",
        "IS_DISABLED",
        "CONCURRENCY_CONTROL_NUMBER",
        "APP_CREATE_TIMESTAMP",
        "APP_CREATE_USERID",
        "APP_CREATE_USER_GUID",
        "APP_CREATE_USER_DIRECTORY",
        "APP_LAST_UPDATE_TIMESTAMP",
        "APP_LAST_UPDATE_USERID",
        "APP_LAST_UPDATE_USER_GUID",
        "APP_LAST_UPDATE_USER_DIRECTORY"
      from inserted;
  
  END TRY
  BEGIN CATCH
     IF @@trancount > 0 ROLLBACK TRANSACTION
     EXEC pims_error_handling
  END CATCH;
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Create foreign key constraint PIM_PIMPRU_PIM_PIMPRV_FK
  PRINT N'Create foreign key constraint PIM_PIMPRU_PIM_PIMPRV_FK'
  GO
  ALTER TABLE [dbo].[PIMS_PROPERTY_IMPROVEMENT]
  	ADD CONSTRAINT [PIM_PIMPRU_PIM_PIMPRV_FK]
  	FOREIGN KEY([PROPERTY_IMPROVEMENT_UOM_TYPE_CODE])
  	REFERENCES [dbo].[PIMS_PROPERTY_IMPROVEMENT_UOM_TYPE]([PROPERTY_IMPROVEMENT_UOM_TYPE_CODE])
  	ON DELETE NO ACTION 
  	ON UPDATE NO ACTION 
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop table pmbc.PMBC_PARCEL_POLYGON_FABRIC
  PRINT N'Drop table pmbc.PMBC_PARCEL_POLYGON_FABRIC'
  GO
  DROP TABLE [pmbc].[PMBC_PARCEL_POLYGON_FABRIC]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop table dbo.PIMS_LEASE_PAYMENT_PERIOD_HIST
  PRINT N'Drop table dbo.PIMS_LEASE_PAYMENT_PERIOD_HIST'
  GO
  DROP TABLE [dbo].[PIMS_LEASE_PAYMENT_PERIOD_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop sequence dbo.PIMS_LEASE_PAYMENT_PERIOD_H_ID_SEQ
  PRINT N'Drop sequence dbo.PIMS_LEASE_PAYMENT_PERIOD_H_ID_SEQ'
  GO
  DROP SEQUENCE [dbo].[PIMS_LEASE_PAYMENT_PERIOD_H_ID_SEQ]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop table dbo.PIMS_LEASE_PAYMENT_FORECAST_HIST
  PRINT N'Drop table dbo.PIMS_LEASE_PAYMENT_FORECAST_HIST'
  GO
  DROP TABLE [dbo].[PIMS_LEASE_PAYMENT_FORECAST_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop sequence dbo.PIMS_LEASE_PAYMENT_FORECAST_H_ID_SEQ
  PRINT N'Drop sequence dbo.PIMS_LEASE_PAYMENT_FORECAST_H_ID_SEQ'
  GO
  DROP SEQUENCE [dbo].[PIMS_LEASE_PAYMENT_FORECAST_H_ID_SEQ]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop table dbo.PIMS_LEASE_PAYMENT_STATUS_TYPE
  PRINT N'Drop table dbo.PIMS_LEASE_PAYMENT_STATUS_TYPE'
  GO
  DROP TABLE [dbo].[PIMS_LEASE_PAYMENT_STATUS_TYPE]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop sequence dbo.PIMS_LEASE_PAYMENT_FORECAST_ID_SEQ
  PRINT N'Drop sequence dbo.PIMS_LEASE_PAYMENT_FORECAST_ID_SEQ'
  GO
  DROP SEQUENCE [dbo].[PIMS_LEASE_PAYMENT_FORECAST_ID_SEQ]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop table dbo.PIMS_LEASE_PAYMENT_HIST
  PRINT N'Drop table dbo.PIMS_LEASE_PAYMENT_HIST'
  GO
  DROP TABLE [dbo].[PIMS_LEASE_PAYMENT_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop sequence dbo.PIMS_LEASE_PAYMENT_H_ID_SEQ
  PRINT N'Drop sequence dbo.PIMS_LEASE_PAYMENT_H_ID_SEQ'
  GO
  DROP SEQUENCE [dbo].[PIMS_LEASE_PAYMENT_H_ID_SEQ]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop table dbo.PIMS_LEASE_PAYMENT_METHOD_TYPE
  PRINT N'Drop table dbo.PIMS_LEASE_PAYMENT_METHOD_TYPE'
  GO
  DROP TABLE [dbo].[PIMS_LEASE_PAYMENT_METHOD_TYPE]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop table dbo.PIMS_LEASE_TERM_HIST
  PRINT N'Drop table dbo.PIMS_LEASE_TERM_HIST'
  GO
  DROP TABLE [dbo].[PIMS_LEASE_TERM_HIST]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop sequence dbo.PIMS_LEASE_TERM_H_ID_SEQ
  PRINT N'Drop sequence dbo.PIMS_LEASE_TERM_H_ID_SEQ'
  GO
  DROP SEQUENCE [dbo].[PIMS_LEASE_TERM_H_ID_SEQ]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop table dbo.PIMS_LEASE_TERM_STATUS_TYPE
  PRINT N'Drop table dbo.PIMS_LEASE_TERM_STATUS_TYPE'
  GO
  DROP TABLE [dbo].[PIMS_LEASE_TERM_STATUS_TYPE]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop table dbo.PIMS_LEASE_RESPONSIBILITY_TYPE
  PRINT N'Drop table dbo.PIMS_LEASE_RESPONSIBILITY_TYPE'
  GO
  DROP TABLE [dbo].[PIMS_LEASE_RESPONSIBILITY_TYPE]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  -- Drop table dbo.PIMS_LEASE_INITIATOR_TYPE
  PRINT N'Drop table dbo.PIMS_LEASE_INITIATOR_TYPE'
  GO
  DROP TABLE [dbo].[PIMS_LEASE_INITIATOR_TYPE]
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  
  COMMIT TRANSACTION
  GO
  IF @@ERROR <> 0 SET NOEXEC ON
  GO
  DECLARE @Success AS BIT
  SET @Success = 1
  SET NOEXEC OFF
  IF (@Success = 1) PRINT 'The database update succeeded'
  ELSE BEGIN
     IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION
     PRINT 'The database update failed'
  END
  GO
  