Tables [dbo].[LaborRatingSchedule]
Properties
PropertyValue
Row Count (~)18
Created8:23:17 AM Friday, December 7, 2018
Last Modified8:36:29 AM Friday, December 7, 2018
Columns
NameData TypeMax Length (Bytes)Allow NullsIdentity
Primary Key PK_LaborRatingSchedule: LaborRatingScheduleIDLaborRatingScheduleIDint4
No
1 - 1
Cluster Key IX_LaborRatingSchedule_LaborRatingGroup_LaborRatingDay_StartTime: LaborRatingGroupFID\LaborRatingDayFID\StartTimeForeign Keys FK_LaborRatingSchedule_LaborRatingGroup: [dbo].[LaborRatingGroup].LaborRatingGroupFIDLaborRatingGroupFIDint4
No
Cluster Key IX_LaborRatingSchedule_LaborRatingGroup_LaborRatingDay_StartTime: LaborRatingGroupFID\LaborRatingDayFID\StartTimeForeign Keys FK_LaborRatingSchedule_LaborRatingDay: [dbo].[LaborRatingDay].LaborRatingDayFIDLaborRatingDayFIDint4
No
Cluster Key IX_LaborRatingSchedule_LaborRatingGroup_LaborRatingDay_StartTime: LaborRatingGroupFID\LaborRatingDayFID\StartTimeStartTimedatetime8
No
Foreign Keys FK_LaborRatingSchedule_LaborRatingType: [dbo].[LaborRatingType].LaborRatingTypeFIDLaborRatingTypeFIDint4
No
Indexes Indexes
NameColumnsUnique
Primary Key PK_LaborRatingSchedule: LaborRatingScheduleIDPK_LaborRatingScheduleLaborRatingScheduleID
Yes
Cluster Key IX_LaborRatingSchedule_LaborRatingGroup_LaborRatingDay_StartTime: LaborRatingGroupFID\LaborRatingDayFID\StartTimeIX_LaborRatingSchedule_LaborRatingGroup_LaborRatingDay_StartTimeLaborRatingGroupFID, LaborRatingDayFID, StartTime
Yes
Triggers Triggers
NameANSI Nulls OnQuoted Identifier OnOn
LaborRatingSchedule_PushChangesAfterInsert
Yes
Yes
After Insert
LaborRatingSchedule_PushChangesAfterUpdate
Yes
Yes
After Update
LaborRatingSchedule_RenormalizeDataForGroupAndDayAfterDelete
Yes
Yes
After Delete
Foreign Keys Foreign Keys
NameDeleteColumns
FK_LaborRatingSchedule_LaborRatingDayLaborRatingDayFID->[dbo].[LaborRatingDay].[LaborRatingDayID]
FK_LaborRatingSchedule_LaborRatingGroupCascadeLaborRatingGroupFID->[dbo].[LaborRatingGroup].[LaborRatingGroupID]
FK_LaborRatingSchedule_LaborRatingTypeLaborRatingTypeFID->[dbo].[LaborRatingType].[LaborRatingTypeID]
Permissions
TypeActionOwning Principal
GrantDeleteMssExec
GrantInsertMssExec
GrantSelectMssExec
GrantUpdateMssExec
SQL Script
CREATE TABLE [dbo].[LaborRatingSchedule]
(
[LaborRatingScheduleID] [int] NOT NULL IDENTITY(1, 1),
[LaborRatingGroupFID] [int] NOT NULL,
[LaborRatingDayFID] [int] NOT NULL,
[StartTime] [datetime] NOT NULL,
[LaborRatingTypeFID] [int] NOT NULL
) ON [PRIMARY]
GO

/*
* Project the change to LaborRatingScheduleQuery
*/

CREATE TRIGGER [dbo].[LaborRatingSchedule_PushChangesAfterInsert]
    ON [dbo].[LaborRatingSchedule]
    AFTER insert
    AS
    begin
        --Admin (the source of this data) will only insert one record at a time.  

        if 1 = (select count(*) from inserted)
        begin
            declare @theLaborRatingDayID int
            declare @theLaborRatingGroupID int

            select
                @theLaborRatingGroupID = inserted.LaborRatingGroupFID,
                @theLaborRatingDayID = inserted.LaborRatingDayFID
            from inserted
            
            exec PushLaborRatingScheduleDataToQuery
                @theLaborRatingGroupID,
                @theLaborRatingDayID
        end
    end
GO


/*
* Project the change to LaborRatingScheduleQuery
*/

CREATE TRIGGER [dbo].[LaborRatingSchedule_PushChangesAfterUpdate]
    ON [dbo].[LaborRatingSchedule]
    AFTER update
    AS
    begin
        --Admin (the source of this data) will only insert one record at a time.  

        if 1 = (select count(*) from inserted)
        begin
            declare @theLaborRatingDayID int
            declare @theLaborRatingGroupID int

            select
                @theLaborRatingGroupID = inserted.LaborRatingGroupFID,
                @theLaborRatingDayID = inserted.LaborRatingDayFID
            from inserted
            
            exec PushLaborRatingScheduleDataToQuery
                @theLaborRatingGroupID,
                @theLaborRatingDayID

            declare @thePreviousLaborRatingDayID int
            select @thePreviousLaborRatingDayID = deleted.LaborRatingDayFID from deleted
            if @thePreviousLaborRatingDayID <> @theLaborRatingDayID
            begin
                exec PushLaborRatingScheduleDataToQuery
                    @theLaborRatingGroupID,
                    @thePreviousLaborRatingDayID
            end
        end
    end
GO

/*
* Project the change to LaborRatingScheduleQuery
*/

CREATE TRIGGER [dbo].[LaborRatingSchedule_RenormalizeDataForGroupAndDayAfterDelete]
    ON [dbo].[LaborRatingSchedule]
    AFTER delete
    AS
    begin
        --Admin (the source of this data) will only insert one record at a time.  

        if 1 = (select count(*) from deleted)
        begin
            declare @theLaborRatingDayID int
            declare @theLaborRatingGroupID int
            
            select
                @theLaborRatingGroupID = deleted.LaborRatingGroupFID,
                @theLaborRatingDayID = deleted.LaborRatingDayFID
            from deleted
            
            exec PushLaborRatingScheduleDataToQuery
                @theLaborRatingGroupID,
                @theLaborRatingDayID
        end
    end
GO
ALTER TABLE [dbo].[LaborRatingSchedule] ADD CONSTRAINT [PK_LaborRatingSchedule] PRIMARY KEY NONCLUSTERED  ([LaborRatingScheduleID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[LaborRatingSchedule] ADD CONSTRAINT [IX_LaborRatingSchedule_LaborRatingGroup_LaborRatingDay_StartTime] UNIQUE CLUSTERED  ([LaborRatingGroupFID], [LaborRatingDayFID], [StartTime]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[LaborRatingSchedule] ADD CONSTRAINT [FK_LaborRatingSchedule_LaborRatingDay] FOREIGN KEY ([LaborRatingDayFID]) REFERENCES [dbo].[LaborRatingDay] ([LaborRatingDayID])
GO
ALTER TABLE [dbo].[LaborRatingSchedule] ADD CONSTRAINT [FK_LaborRatingSchedule_LaborRatingGroup] FOREIGN KEY ([LaborRatingGroupFID]) REFERENCES [dbo].[LaborRatingGroup] ([LaborRatingGroupID]) ON DELETE CASCADE
GO
ALTER TABLE [dbo].[LaborRatingSchedule] ADD CONSTRAINT [FK_LaborRatingSchedule_LaborRatingType] FOREIGN KEY ([LaborRatingTypeFID]) REFERENCES [dbo].[LaborRatingType] ([LaborRatingTypeID])
GO
GRANT SELECT ON  [dbo].[LaborRatingSchedule] TO [MssExec]
GRANT INSERT ON  [dbo].[LaborRatingSchedule] TO [MssExec]
GRANT DELETE ON  [dbo].[LaborRatingSchedule] TO [MssExec]
GRANT UPDATE ON  [dbo].[LaborRatingSchedule] TO [MssExec]
GO
Uses