CREATE TABLE [dbo].[arg_rel_cont_ent]
(
[relationship_id] [bigint] NOT NULL,
[object_uuid] [binary] (16) NOT NULL,
[ac1ivid] [int] NULL,
[acdatedt] [datetime] NULL,
[actimetm] [nvarchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[accommnt] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[actext1] [nvarchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[acint1] [int] NULL,
[acdate1] [datetime] NULL,
[secondary_object_uuid] [binary] (16) NOT NULL,
[lk2ivid] [int] NULL,
[lkinstnc] [int] NULL,
[lkstrtdt] [datetime] NULL,
[lkenddt] [datetime] NULL,
[lkcommnt] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[creation_user] [nvarchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[creation_date] [int] NULL,
[last_update_user] [nvarchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[last_update_date] [int] NULL,
[version_number] [int] NULL CONSTRAINT [DF__ARG_REL_C__VERSI__18027DF1] DEFAULT ('0'),
[inactive] [int] NOT NULL CONSTRAINT [DF__ARG_REL_C__INACT__18F6A22A] DEFAULT ('0 '),
[tenant] [binary] (16) NULL
) ON [PRIMARY]
GO
CREATE TRIGGER dbo.ca_tr_del_arg_rel_cont_ent
ON dbo.arg_rel_cont_ent
FOR DELETE AS
DECLARE
@audit_product nvarchar(64)
SET @audit_product = APP_NAME()
INSERT INTO dbo.aud_arg_rel_cont_ent (
AUDIT_TRAIL_PRODUCT,
AUDIT_TRAIL_USER,
AUDIT_TRAIL_TYPE,
AUDIT_TRAIL_DATE,
relationship_id,
object_uuid,
ac1ivid,
acdatedt,
actimetm,
accommnt,
actext1,
acint1,
acdate1,
secondary_object_uuid,
lk2ivid,
lkinstnc,
lkstrtdt,
lkenddt,
lkcommnt,
creation_user,
creation_date,
last_update_user,
last_update_date,
version_number,
inactive,
tenant) SELECT
@audit_product,old.last_update_user, 'DELETE', datediff(ss, '1/1/1970', getutcdate()),
old.relationship_id,
old.object_uuid,
old.ac1ivid,
old.acdatedt,
old.actimetm,
old.accommnt,
old.actext1,
old.acint1,
old.acdate1,
old.secondary_object_uuid,
old.lk2ivid,
old.lkinstnc,
old.lkstrtdt,
old.lkenddt,
old.lkcommnt,
old.creation_user,
old.creation_date,
old.last_update_user,
old.last_update_date,
old.version_number,
old.inactive,
old.tenant
FROM deleted old
GO
CREATE TRIGGER dbo.ca_tr_ins_arg_rel_cont_ent
ON dbo.arg_rel_cont_ent
FOR INSERT AS
DECLARE
@audit_product nvarchar(64)
SET @audit_product = APP_NAME()
INSERT INTO dbo.aud_arg_rel_cont_ent (
AUDIT_TRAIL_PRODUCT,
AUDIT_TRAIL_USER,
AUDIT_TRAIL_TYPE,
AUDIT_TRAIL_DATE,
relationship_id,
object_uuid,
ac1ivid,
acdatedt,
actimetm,
accommnt,
actext1,
acint1,
acdate1,
secondary_object_uuid,
lk2ivid,
lkinstnc,
lkstrtdt,
lkenddt,
lkcommnt,
creation_user,
creation_date,
last_update_user,
last_update_date,
version_number,
inactive,
tenant) SELECT
@audit_product, new.last_update_user, 'INSERT', datediff(ss, '1/1/1970', getutcdate()),
new.relationship_id,
new.object_uuid,
new.ac1ivid,
new.acdatedt,
new.actimetm,
new.accommnt,
new.actext1,
new.acint1,
new.acdate1,
new.secondary_object_uuid,
new.lk2ivid,
new.lkinstnc,
new.lkstrtdt,
new.lkenddt,
new.lkcommnt,
new.creation_user,
new.creation_date,
new.last_update_user,
new.last_update_date,
new.version_number,
new.inactive,
new.tenant
FROM inserted new
GO
CREATE TRIGGER dbo.ca_tr_upd_arg_rel_cont_ent
ON dbo.arg_rel_cont_ent
FOR UPDATE AS
DECLARE
@audit_product nvarchar(64),
@last_update_user nvarchar(64),
@version_number int
SET @audit_product = APP_NAME()
SELECT @version_number = version_number, @last_update_user = last_update_user FROM inserted
IF @version_number != -1
INSERT INTO dbo.aud_arg_rel_cont_ent (
AUDIT_TRAIL_PRODUCT,
AUDIT_TRAIL_USER,
AUDIT_TRAIL_TYPE,
AUDIT_TRAIL_DATE,
relationship_id,
object_uuid,
ac1ivid,
acdatedt,
actimetm,
accommnt,
actext1,
acint1,
acdate1,
secondary_object_uuid,
lk2ivid,
lkinstnc,
lkstrtdt,
lkenddt,
lkcommnt,
creation_user,
creation_date,
last_update_user,
last_update_date,
version_number,
inactive,
tenant) SELECT
@audit_product, new.last_update_user, 'UPDATE', datediff(ss, '1/1/1970', getutcdate()),
new.relationship_id,
new.object_uuid,
new.ac1ivid,
new.acdatedt,
new.actimetm,
new.accommnt,
new.actext1,
new.acint1,
new.acdate1,
new.secondary_object_uuid,
new.lk2ivid,
new.lkinstnc,
new.lkstrtdt,
new.lkenddt,
new.lkcommnt,
new.creation_user,
new.creation_date,
new.last_update_user,
new.last_update_date,
new.version_number,
new.inactive,
new.tenant
FROM inserted new
GO
ALTER TABLE [dbo].[arg_rel_cont_ent] ADD CONSTRAINT [pkrel_cont_ent] PRIMARY KEY CLUSTERED ([relationship_id]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [rel_cont_ent_idx01] ON [dbo].[arg_rel_cont_ent] ([object_uuid], [secondary_object_uuid]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[arg_rel_cont_ent] ADD CONSTRAINT [CONT_ENT_ASSET_FK01] FOREIGN KEY ([object_uuid]) REFERENCES [dbo].[ca_owned_resource] ([own_resource_uuid])
GO
ALTER TABLE [dbo].[arg_rel_cont_ent] ADD CONSTRAINT [CONT_ENT_CONT_FK02] FOREIGN KEY ([secondary_object_uuid]) REFERENCES [dbo].[ca_contact] ([contact_uuid])
GO
ALTER TABLE [dbo].[arg_rel_cont_ent] ADD CONSTRAINT [FK_CONT_ENT_TENANT] FOREIGN KEY ([tenant]) REFERENCES [dbo].[ca_tenant] ([id])
GO