CREATE TABLE [dbo].[LaborRatingGroup]
(
[LaborRatingGroupID] [int] NOT NULL IDENTITY(1, 1),
[Name] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[OTAfter8Hours] [bit] NOT NULL CONSTRAINT [DF_LaborRatingGroup_OTAfter8Hours] DEFAULT ((0))
) ON [PRIMARY]
GO
CREATE TRIGGER [dbo].[LaborRatingGroup_CreateEmptyScheduleWhenCreated]
ON [dbo].[LaborRatingGroup]
AFTER INSERT
AS
BEGIN
set nocount on
insert into LaborRatingScheduleQuery
(
LaborRatingGroupFID,
LaborRatingDayFID,
StartTime,
EndTime,
LaborRatingTypeFID
)
select
LaborRatingGroupFID = inserted.LaborRatingGroupID,
LaborRatingDayFID = LaborRatingDay.LaborRatingDayID,
StartTime = convert(datetime, 0),
EndTime = convert(datetime, 1),
LaborRatingTypeFID = LaborRatingType.LaborRatingTypeID
from inserted
cross join LaborRatingDay
cross join LaborRatingType
where LaborRatingType.TypeName = 'Regular Rate'
end
GO
ALTER TABLE [dbo].[LaborRatingGroup] ADD CONSTRAINT [PK_LaborRatingGroup] PRIMARY KEY CLUSTERED ([LaborRatingGroupID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[LaborRatingGroup] ADD CONSTRAINT [IX_LaborRatingGroup_Name] UNIQUE NONCLUSTERED ([Name]) ON [PRIMARY]
GO
GRANT SELECT ON [dbo].[LaborRatingGroup] TO [MssExec]
GRANT INSERT ON [dbo].[LaborRatingGroup] TO [MssExec]
GRANT DELETE ON [dbo].[LaborRatingGroup] TO [MssExec]
GRANT UPDATE ON [dbo].[LaborRatingGroup] TO [MssExec]
GO