CREATE TABLE [dbo].[gla_objects]
(
[obj_id] [int] NOT NULL,
[agent_id] [int] NOT NULL,
[scan_index] [int] NOT NULL,
[object_name] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL
) ON [PRIMARY]
GO
CREATE TRIGGER TD_GLA_OBJECTS ON GLA_OBJECTS AFTER DELETE
AS
declare @numrows INTEGER
select @numrows = count(*)
from GLA_HOURS
where gla_hours.obj_id = obj_id
IF @numrows > 0
BEGIN
RAISERROR ('Cannot DELETE gla_objects because gla_hours exists.', 16, 1)
END
GO
CREATE TRIGGER TI_GLA_OBJECTS ON GLA_OBJECTS AFTER INSERT
AS
declare @numrows INTEGER
select @numrows = count(*)
from GLA_SDAMAPS
where
scan_index = gla_sdamaps.scan_index and
agent_id = gla_sdamaps.agent_id
IF @numrows = 0
BEGIN
RAISERROR ('Cannot INSERT gla_objects because gla_sdamaps does not exist.', 16, 1)
END
GO
CREATE TRIGGER TU_GLA_OBJECTS ON GLA_OBJECTS AFTER UPDATE
AS
declare @numrows INTEGER
select @numrows = count(*)
from GLA_HOURS
where gla_hours.obj_id = obj_id
IF @numrows > 0
BEGIN
RAISERROR ('Cannot UPDATE gla_objects because gla_hours exists.', 16, 1)
END
select @numrows = count(*)
from gla_sdamaps
where
scan_index = gla_sdamaps.scan_index and
agent_id = gla_sdamaps.agent_id;
IF @numrows = 0
BEGIN
RAISERROR ('Cannot UPDATE gla_sdamaps because gla_agents does not exist.', 16, 1)
END
GO
ALTER TABLE [dbo].[gla_objects] ADD CONSTRAINT [$gla_o_u000019bd00000000] PRIMARY KEY CLUSTERED ([obj_id]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [xif39gla_objects] ON [dbo].[gla_objects] ([scan_index], [agent_id]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[gla_objects] ADD CONSTRAINT [$gla_o_r000019d100000000] FOREIGN KEY ([scan_index], [agent_id]) REFERENCES [dbo].[gla_sdamaps] ([scan_index], [agent_id])
GO